dependencies#
Application dependency layer
Application dependency providers.
- class app.lib.dependencies.BeforeAfter(field_name: str, before: datetime | None, after: datetime | None)[source]#
Bases:
StatementFilter
Data required to filter a query on a
datetime
column.
- class app.lib.dependencies.CollectionFilter(field_name: str, values: Collection[T] | None)[source]#
Bases:
InAnyFilter
,Generic
[T
]Data required to construct a
WHERE ... IN (...)
clause.- 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.
- __init__(field_name: str, values: Collection[T] | None) None #
- class app.lib.dependencies.LimitOffset(limit: int, offset: int)[source]#
Bases:
PaginationFilter
Data required to add limit/offset filtering to a query.
- class app.lib.dependencies.OrderBy(field_name: str, sort_order: Literal['asc', 'desc'] = 'asc')[source]#
Bases:
StatementFilter
Data required to construct a
ORDER BY ...
clause.
- class app.lib.dependencies.SearchFilter(field_name: str | set[str], value: str, ignore_case: bool | None = False)[source]#
Bases:
StatementFilter
Data required to construct a
WHERE field_name LIKE '%' || :value || '%'
clause.
- app.lib.dependencies.create_collection_dependencies() dict[str, Provide] [source]#
Create ORM dependencies.
Creates a dictionary of provides for pagination endpoints.
- app.lib.dependencies.provide_created_filter(before: ~datetime.datetime | None = ParameterKwarg(examples=None, external_docs=None, content_encoding=None, default=None, title=None, description=None, const=None, gt=None, ge=None, lt=None, le=None, multiple_of=None, min_items=None, max_items=None, min_length=None, max_length=None, pattern=None, lower_case=None, upper_case=None, format=None, enum=None, read_only=None, schema_extra=None, schema_component_key=None, annotation=<_EmptyEnum.EMPTY: 0>, header=None, cookie=None, query='createdBefore', required=False), after: ~datetime.datetime | None = ParameterKwarg(examples=None, external_docs=None, content_encoding=None, default=None, title=None, description=None, const=None, gt=None, ge=None, lt=None, le=None, multiple_of=None, min_items=None, max_items=None, min_length=None, max_length=None, pattern=None, lower_case=None, upper_case=None, format=None, enum=None, read_only=None, schema_extra=None, schema_component_key=None, annotation=<_EmptyEnum.EMPTY: 0>, header=None, cookie=None, query='createdAfter', required=False)) BeforeAfter [source]#
Return type consumed by Repository.filter_on_datetime_field().
- Parameters:
before (DTorNone) – Filter for records created before this date/time.
after (DTorNone) – Filter for records created after this date/time.
- Returns:
Filter for scoping query to instance creation date/time.
- Return type:
- app.lib.dependencies.provide_filter_dependencies(created_filter: BeforeAfter = DependencyKwarg(default=<_EmptyEnum.EMPTY: 0>, skip_validation=True), updated_filter: BeforeAfter = DependencyKwarg(default=<_EmptyEnum.EMPTY: 0>, skip_validation=True), id_filter: CollectionFilter = DependencyKwarg(default=<_EmptyEnum.EMPTY: 0>, skip_validation=True), limit_offset: LimitOffset = DependencyKwarg(default=<_EmptyEnum.EMPTY: 0>, skip_validation=True), search_filter: SearchFilter = DependencyKwarg(default=<_EmptyEnum.EMPTY: 0>, skip_validation=True), order_by: OrderBy = DependencyKwarg(default=<_EmptyEnum.EMPTY: 0>, skip_validation=True)) list[FilterTypes] [source]#
Provide common collection route filtering dependencies.
Add all filters to any route by including this function as a dependency, e.g.:
@get def get_collection_handler(filters: Filters) -> ...: ...
The dependency is provided in the application layer, so only need to inject the dependency where necessary.
- Parameters:
created_filter (BeforeAfter) – Filter for a scoping query to instance creation date/time.
updated_filter (BeforeAfter) – Filter for a scoping query to instance update date/time.
id_filter (CollectionFilter) – Filter for a scoping query to a limited set of identities.
limit_offset (LimitOffset) – Filter for query pagination.
search_filter (SearchFilter) – Filter for searching fields.
order_by (OrderBy) – Order by for query.
- Returns:
List of filters parsed from connection.
- Return type:
list[FilterTypes]
- app.lib.dependencies.provide_id_filter(ids: list[~uuid.UUID] | None = ParameterKwarg(examples=None, external_docs=None, content_encoding=None, default=None, title=None, description=None, const=None, gt=None, ge=None, lt=None, le=None, multiple_of=None, min_items=None, max_items=None, min_length=None, max_length=None, pattern=None, lower_case=None, upper_case=None, format=None, enum=None, read_only=None, schema_extra=None, schema_component_key=None, annotation=<_EmptyEnum.EMPTY: 0>, header=None, cookie=None, query='ids', required=False)) CollectionFilter[UUID] [source]#
Return type consumed by
Repository.filter_in_collection()
.- Parameters:
ids (list[UUID] | None) – Parsed out of a comma-separated list of values in query params.
- Returns:
Filter for a scoping query to a limited set of identities.
- Return type:
CollectionFilter[UUID]
- app.lib.dependencies.provide_limit_offset_pagination(current_page: int = ParameterKwarg(examples=None, external_docs=None, content_encoding=None, default=1, title=None, description=None, const=None, gt=None, ge=1, lt=None, le=None, multiple_of=None, min_items=None, max_items=None, min_length=None, max_length=None, pattern=None, lower_case=None, upper_case=None, format=None, enum=None, read_only=None, schema_extra=None, schema_component_key=None, annotation=<_EmptyEnum.EMPTY: 0>, header=None, cookie=None, query='currentPage', required=False), page_size: int = ParameterKwarg(examples=None, external_docs=None, content_encoding=None, default=20, title=None, description=None, const=None, gt=None, ge=1, lt=None, le=None, multiple_of=None, min_items=None, max_items=None, min_length=None, max_length=None, pattern=None, lower_case=None, upper_case=None, format=None, enum=None, read_only=None, schema_extra=None, schema_component_key=None, annotation=<_EmptyEnum.EMPTY: 0>, header=None, cookie=None, query='pageSize', required=False)) LimitOffset [source]#
Add offset/limit pagination.
Return type consumed by
Repository.apply_limit_offset_pagination()
.- Parameters:
- Returns:
Filter for query pagination.
- Return type:
- app.lib.dependencies.provide_order_by(field_name: str | None = ParameterKwarg(examples=None, external_docs=None, content_encoding=None, default=None, title='Order by field', description=None, const=None, gt=None, ge=None, lt=None, le=None, multiple_of=None, min_items=None, max_items=None, min_length=None, max_length=None, pattern=None, lower_case=None, upper_case=None, format=None, enum=None, read_only=None, schema_extra=None, schema_component_key=None, annotation=<_EmptyEnum.EMPTY: 0>, header=None, cookie=None, query='orderBy', required=False), sort_order: ~typing.Literal['asc', 'desc'] | None = ParameterKwarg(examples=None, external_docs=None, content_encoding=None, default='desc', title='Field to search', description=None, const=None, gt=None, ge=None, lt=None, le=None, multiple_of=None, min_items=None, max_items=None, min_length=None, max_length=None, pattern=None, lower_case=None, upper_case=None, format=None, enum=None, read_only=None, schema_extra=None, schema_component_key=None, annotation=<_EmptyEnum.EMPTY: 0>, header=None, cookie=None, query='sortOrder', required=False)) OrderBy [source]#
Add offset/limit pagination.
Return type consumed by
Repository.apply_order_by()
.- Parameters:
field_name (StringOrNone) – Field name to order by.
sort_order (SortOrderOrNone) – Order field ascending (‘asc’) or descending (‘desc)
- Returns:
Order by for query.
- Return type:
- app.lib.dependencies.provide_search_filter(field: str | None = ParameterKwarg(examples=None, external_docs=None, content_encoding=None, default=None, title='Field to search', description=None, const=None, gt=None, ge=None, lt=None, le=None, multiple_of=None, min_items=None, max_items=None, min_length=None, max_length=None, pattern=None, lower_case=None, upper_case=None, format=None, enum=None, read_only=None, schema_extra=None, schema_component_key=None, annotation=<_EmptyEnum.EMPTY: 0>, header=None, cookie=None, query='searchField', required=False), search: str | None = ParameterKwarg(examples=None, external_docs=None, content_encoding=None, default=None, title='Field to search', description=None, const=None, gt=None, ge=None, lt=None, le=None, multiple_of=None, min_items=None, max_items=None, min_length=None, max_length=None, pattern=None, lower_case=None, upper_case=None, format=None, enum=None, read_only=None, schema_extra=None, schema_component_key=None, annotation=<_EmptyEnum.EMPTY: 0>, header=None, cookie=None, query='searchString', required=False), ignore_case: bool | None = ParameterKwarg(examples=None, external_docs=None, content_encoding=None, default=None, title='Search should be case sensitive', description=None, const=None, gt=None, ge=None, lt=None, le=None, multiple_of=None, min_items=None, max_items=None, min_length=None, max_length=None, pattern=None, lower_case=None, upper_case=None, format=None, enum=None, read_only=None, schema_extra=None, schema_component_key=None, annotation=<_EmptyEnum.EMPTY: 0>, header=None, cookie=None, query='searchIgnoreCase', required=False)) SearchFilter [source]#
Add offset/limit pagination.
Return type consumed by Repository.apply_search_filter().
- Parameters:
field (StringOrNone) – Field name to search.
search (StringOrNone) – Value to search for.
ignore_case (BooleanOrNone) – Whether to ignore case when searching.
- Returns:
Filter for searching fields.
- Return type:
- app.lib.dependencies.provide_updated_filter(before: ~datetime.datetime | None = ParameterKwarg(examples=None, external_docs=None, content_encoding=None, default=None, title=None, description=None, const=None, gt=None, ge=None, lt=None, le=None, multiple_of=None, min_items=None, max_items=None, min_length=None, max_length=None, pattern=None, lower_case=None, upper_case=None, format=None, enum=None, read_only=None, schema_extra=None, schema_component_key=None, annotation=<_EmptyEnum.EMPTY: 0>, header=None, cookie=None, query='updatedBefore', required=False), after: ~datetime.datetime | None = ParameterKwarg(examples=None, external_docs=None, content_encoding=None, default=None, title=None, description=None, const=None, gt=None, ge=None, lt=None, le=None, multiple_of=None, min_items=None, max_items=None, min_length=None, max_length=None, pattern=None, lower_case=None, upper_case=None, format=None, enum=None, read_only=None, schema_extra=None, schema_component_key=None, annotation=<_EmptyEnum.EMPTY: 0>, header=None, cookie=None, query='updatedAfter', required=False)) BeforeAfter [source]#
Add updated filter.
Return type consumed by
Repository.filter_on_datetime_field()
.- Parameters:
before (DTorNone) – Filter for records updated before this date/time.
after (DTorNone) – Filter for records updated after this date/time.
- Returns:
Filter for scoping query to instance update date/time.
- Return type: