-
-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(repositories): fix #2358 by re-exporting filters and exceptions f…
…rom advanced-alchemy (#2360) * fix(repositories): fix #2358 by re-exporting filters and exceptions from advanced-alchemy Signed-off-by: Janek Nouvertné <[email protected]> * fix docs Signed-off-by: Janek Nouvertné <[email protected]> * fix: pin adv alchemy to v0.2.2 * Update pyproject.toml * update poetry.lock Signed-off-by: Janek Nouvertné <[email protected]> --------- Signed-off-by: Janek Nouvertné <[email protected]> Co-authored-by: Cody Fincher <[email protected]>
- Loading branch information
1 parent
42e4914
commit fd18f36
Showing
11 changed files
with
485 additions
and
401 deletions.
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
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,5 +1,4 @@ | ||
exceptions | ||
========== | ||
|
||
.. automodule:: litestar.repository.exceptions | ||
:members: | ||
This page has moved to :doc:`advanced-alchemy:reference/filters` |
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,5 +1,4 @@ | ||
filters | ||
======= | ||
|
||
.. automodule:: litestar.repository.filters | ||
:members: | ||
This page has moved to :doc:`advanced-alchemy:reference/filters` |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from __future__ import annotations | ||
|
||
__all__ = ("ConflictError", "NotFoundError", "RepositoryError") | ||
|
||
|
||
class RepositoryError(Exception): | ||
"""Base repository exception type.""" | ||
|
||
|
||
class ConflictError(RepositoryError): | ||
"""Data integrity error.""" | ||
|
||
|
||
class NotFoundError(RepositoryError): | ||
"""An identity does not exist.""" |
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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
"""Collection filter datastructures.""" | ||
from __future__ import annotations | ||
|
||
from collections import abc # noqa: TCH003 | ||
from dataclasses import dataclass | ||
from datetime import datetime # noqa: TCH003 | ||
from typing import TYPE_CHECKING, Any, Generic, Literal, TypeVar | ||
|
||
if TYPE_CHECKING: | ||
from typing_extensions import TypeAlias | ||
|
||
T = TypeVar("T") | ||
|
||
__all__ = ( | ||
"BeforeAfter", | ||
"CollectionFilter", | ||
"FilterTypes", | ||
"LimitOffset", | ||
"OrderBy", | ||
"SearchFilter", | ||
"NotInCollectionFilter", | ||
"OnBeforeAfter", | ||
"NotInSearchFilter", | ||
) | ||
|
||
|
||
FilterTypes: TypeAlias = "BeforeAfter | OnBeforeAfter | CollectionFilter[Any] | LimitOffset | OrderBy | SearchFilter | NotInCollectionFilter[Any] | NotInSearchFilter" | ||
"""Aggregate type alias of the types supported for collection filtering.""" | ||
|
||
|
||
@dataclass | ||
class BeforeAfter: | ||
"""Data required to filter a query on a ``datetime`` column.""" | ||
|
||
field_name: str | ||
"""Name of the model attribute to filter on.""" | ||
before: datetime | None | ||
"""Filter results where field earlier than this.""" | ||
after: datetime | None | ||
"""Filter results where field later than this.""" | ||
|
||
|
||
@dataclass | ||
class OnBeforeAfter: | ||
"""Data required to filter a query on a ``datetime`` column.""" | ||
|
||
field_name: str | ||
"""Name of the model attribute to filter on.""" | ||
on_or_before: datetime | None | ||
"""Filter results where field is on or earlier than this.""" | ||
on_or_after: datetime | None | ||
"""Filter results where field on or later than this.""" | ||
|
||
|
||
@dataclass | ||
class CollectionFilter(Generic[T]): | ||
"""Data required to construct a ``WHERE ... IN (...)`` clause.""" | ||
|
||
field_name: str | ||
"""Name of the model attribute to filter on.""" | ||
values: abc.Collection[T] | ||
"""Values for ``IN`` clause.""" | ||
|
||
|
||
@dataclass | ||
class NotInCollectionFilter(Generic[T]): | ||
"""Data required to construct a ``WHERE ... NOT IN (...)`` clause.""" | ||
|
||
field_name: str | ||
"""Name of the model attribute to filter on.""" | ||
values: abc.Collection[T] | ||
"""Values for ``NOT IN`` clause.""" | ||
|
||
|
||
@dataclass | ||
class LimitOffset: | ||
"""Data required to add limit/offset filtering to a query.""" | ||
|
||
limit: int | ||
"""Value for ``LIMIT`` clause of query.""" | ||
offset: int | ||
"""Value for ``OFFSET`` clause of query.""" | ||
|
||
|
||
@dataclass | ||
class OrderBy: | ||
"""Data required to construct a ``ORDER BY ...`` clause.""" | ||
|
||
field_name: str | ||
"""Name of the model attribute to sort on.""" | ||
sort_order: Literal["asc", "desc"] = "asc" | ||
"""Sort ascending or descending""" | ||
|
||
|
||
@dataclass | ||
class SearchFilter: | ||
"""Data required to construct a ``WHERE field_name LIKE '%' || :value || '%'`` clause.""" | ||
|
||
field_name: str | ||
"""Name of the model attribute to sort on.""" | ||
value: str | ||
"""Values for ``LIKE`` clause.""" | ||
ignore_case: bool | None = False | ||
"""Should the search be case insensitive.""" | ||
|
||
|
||
@dataclass | ||
class NotInSearchFilter: | ||
"""Data required to construct a ``WHERE field_name NOT LIKE '%' || :value || '%'`` clause.""" | ||
|
||
field_name: str | ||
"""Name of the model attribute to search on.""" | ||
value: str | ||
"""Values for ``NOT LIKE`` clause.""" | ||
ignore_case: bool | None = False | ||
"""Should the search be case insensitive.""" |
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,15 +1,6 @@ | ||
from __future__ import annotations | ||
try: | ||
from advanced_alchemy.exceptions import ConflictError, NotFoundError, RepositoryError | ||
except ImportError: | ||
from ._exceptions import ConflictError, NotFoundError, RepositoryError # type: ignore[assignment] | ||
|
||
__all__ = ("ConflictError", "NotFoundError", "RepositoryError") | ||
|
||
|
||
class RepositoryError(Exception): | ||
"""Base repository exception type.""" | ||
|
||
|
||
class ConflictError(RepositoryError): | ||
"""Data integrity error.""" | ||
|
||
|
||
class NotFoundError(RepositoryError): | ||
"""An identity does not exist.""" |
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
Oops, something went wrong.