filters

Collection filter datastructures.

class advanced_alchemy.filters.BeforeAfter[source]

Bases: StatementFilter

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.

append_to_statement(statement: Select[tuple[ModelT]], model: type[ModelT]) Select[tuple[ModelT]][source]
append_to_lambda_statement(statement: StatementLambdaElement, model: type[ModelT]) StatementLambdaElement[source]
__init__(field_name: str, before: datetime | None, after: datetime | None) None
class advanced_alchemy.filters.CollectionFilter[source]

Bases: InAnyFilter, Generic[T]

Data required to construct a WHERE ... IN (...) clause.

field_name: str

Name of the model attribute to filter on.

values: Collection[T] | None

Values for IN clause.

An empty list will return an empty result set, however, if None, the filter is not applied to the query, and all rows are returned.

append_to_statement(statement: Select[tuple[ModelT]], model: type[ModelT], prefer_any: bool = False) Select[tuple[ModelT]][source]
append_to_lambda_statement(statement: StatementLambdaElement, model: type[ModelT], prefer_any: bool = False) StatementLambdaElement[source]
__init__(field_name: str, values: Collection[T] | None) None
advanced_alchemy.filters.FilterTypes: TypeAlias = 'BeforeAfter | OnBeforeAfter | CollectionFilter[Any] | LimitOffset | OrderBy | SearchFilter | NotInCollectionFilter[Any] | NotInSearchFilter'

Aggregate type alias of the types supported for collection filtering.

class advanced_alchemy.filters.LimitOffset[source]

Bases: PaginationFilter

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.

append_to_statement(statement: Select[tuple[ModelT]], model: type[ModelT]) Select[tuple[ModelT]][source]
append_to_lambda_statement(statement: StatementLambdaElement, model: type[ModelT]) StatementLambdaElement[source]
__init__(limit: int, offset: int) None
class advanced_alchemy.filters.OrderBy[source]

Bases: StatementFilter

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

__init__(field_name: str, sort_order: Literal['asc', 'desc'] = 'asc') None
append_to_statement(statement: Select[tuple[ModelT]], model: type[ModelT]) Select[tuple[ModelT]][source]
append_to_lambda_statement(statement: StatementLambdaElement, model: type[ModelT]) StatementLambdaElement[source]
class advanced_alchemy.filters.SearchFilter[source]

Bases: StatementFilter

Data required to construct a WHERE field_name LIKE '%' || :value || '%' clause.

__init__(field_name: str | set[str], value: str, ignore_case: bool | None = False) None
field_name: str | set[str]

Name of the model attribute to search on.

value: str

Search value.

ignore_case: bool | None = False

Should the search be case insensitive.

property normalized_field_names: set[str]
get_search_clauses(model: type[ModelT]) list[sqlalchemy.sql.elements.BinaryExpression[bool]][source]
append_to_statement(statement: Select[tuple[ModelT]], model: type[ModelT]) Select[tuple[ModelT]][source]
append_to_lambda_statement(statement: StatementLambdaElement, model: type[ModelT]) StatementLambdaElement[source]
class advanced_alchemy.filters.NotInCollectionFilter[source]

Bases: InAnyFilter, Generic[T]

Data required to construct a WHERE ... NOT IN (...) clause.

field_name: str

Name of the model attribute to filter on.

values: Collection[T] | None

Values for NOT IN clause.

An empty list or None will return all rows.

append_to_statement(statement: Select[tuple[ModelT]], model: type[ModelT], prefer_any: bool = False) Select[tuple[ModelT]][source]
append_to_lambda_statement(statement: StatementLambdaElement, model: type[ModelT], prefer_any: bool = False) StatementLambdaElement[source]
__init__(field_name: str, values: Collection[T] | None) None
class advanced_alchemy.filters.OnBeforeAfter[source]

Bases: StatementFilter

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.

append_to_statement(statement: Select[tuple[ModelT]], model: type[ModelT]) Select[tuple[ModelT]][source]
append_to_lambda_statement(statement: StatementLambdaElement, model: type[ModelT]) StatementLambdaElement[source]
__init__(field_name: str, on_or_before: datetime | None, on_or_after: datetime | None) None
class advanced_alchemy.filters.NotInSearchFilter[source]

Bases: SearchFilter

Data required to construct a WHERE field_name NOT LIKE '%' || :value || '%' clause.

__init__(field_name: str | set[str], value: str, ignore_case: bool | None = False) None
class advanced_alchemy.filters.PaginationFilter[source]

Bases: StatementFilter, ABC

Subclass for methods that function as a pagination type.

class advanced_alchemy.filters.InAnyFilter[source]

Bases: StatementFilter, ABC

Subclass for methods that have a prefer_any attribute.

class advanced_alchemy.filters.StatementFilter[source]

Bases: ABC

abstract append_to_statement(statement: Select[tuple[ModelT]], model: type[ModelT]) Select[tuple[ModelT]][source]
abstract append_to_lambda_statement(statement: StatementLambdaElement, *args: Any, **kwargs: Any) StatementLambdaElement[source]