This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(repository): __class_getitem__ sets
model_type
on repo.
- Loading branch information
1 parent
7fb352e
commit d81e6c6
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,38 @@ | ||
"""Repository type definitions.""" | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
from typing import TYPE_CHECKING, Any, Protocol, TypeVar | ||
|
||
from starlite_saqlalchemy.repository.filters import ( | ||
BeforeAfter, | ||
CollectionFilter, | ||
LimitOffset, | ||
) | ||
|
||
if TYPE_CHECKING: | ||
from pydantic import BaseModel | ||
|
||
FilterTypes = BeforeAfter | CollectionFilter[Any] | LimitOffset | ||
"""Aggregate type alias of the types supported for collection filtering.""" | ||
|
||
|
||
T = TypeVar("T") | ||
|
||
|
||
class ModelProtocol(Protocol): # pylint: disable=too-few-public-methods | ||
"""Protocol for repository models.""" | ||
|
||
@classmethod | ||
def from_dto(cls: type[T], dto_instance: BaseModel) -> T: # pragma: no cover | ||
""" | ||
Args: | ||
dto_instance: A pydantic model. | ||
Returns: | ||
Instance of type with values populated from `dto_instance`. | ||
""" | ||
... # pylint: disable=unnecessary-ellipsis | ||
|
||
|
||
ModelT = TypeVar("ModelT", bound=ModelProtocol) |