Memory Repositories#
Mock repositories evaluate basic column predicates against loaded model values.
Boolean and null literals in comparisons retain SQL filtering semantics, including
is_(True), is_not(False), and is_(None). SQL function expressions require
a database-backed repository.
Async Memory Repositories#
- class advanced_alchemy.repository.memory.SQLAlchemyAsyncMockRepository(
- *,
- statement=None,
- session,
- model_type=None,
- auto_expunge=False,
- auto_refresh=True,
- auto_commit=False,
- order_by=None,
- error_messages=Empty,
- wrap_exceptions=True,
- load=None,
- execution_options=None,
- uniquify=None,
- **kwargs,
Bases:
ModelRepositoryMixin[ModelT],SQLAlchemyAsyncRepositoryProtocol[ModelT]In memory repository.
- async list_and_count(
- *filters,
- statement=None,
- auto_expunge=None,
- count_with_window_function=None,
- order_by=None,
- error_messages=Empty,
- load=None,
- execution_options=None,
- uniquify=None,
- use_cache=True,
- bind_group=None,
- **kwargs,
List of records and total count returned by query.
Deprecated since version 1.10.0: Use
get_many_and_count()instead.- Return type:
tuple[List[ModelT], int]
- async list(
- *filters,
- uniquify=None,
- use_cache=True,
- bind_group=None,
- **kwargs,
List of records returned by query.
Deprecated since version 1.10.0: Use
get_many()instead.- Return type:
List[ModelT]
- class advanced_alchemy.repository.memory.SQLAlchemyAsyncMockSlugRepository#
Bases:
SQLAlchemyAsyncMockRepository[ModelT],SQLAlchemyAsyncSlugRepositoryMixin[ModelT],SQLAlchemyAsyncSlugRepositoryProtocol[ModelT]In-memory repository supporting slug operations.
- async get_by_slug(
- slug,
- error_messages=Empty,
- load=None,
- execution_options=None,
- uniquify=None,
- bind_group=None,
- **kwargs,
Select record by slug value.
- Returns:
The model instance or None if not found.
- Return type:
ModelT | None
- async get_available_slug(
- value_to_slugify,
- **kwargs,
Get a unique slug for the supplied value.
If the value is found to exist, a random 4 digit character is appended to the end.
Override this method to change the default behavior
- Parameters:
value_to_slugify (
str) – A string that should be converted to a unique slug.**kwargs (Any) – Additional parameters.
- Returns:
a unique slug for the supplied value. This is safe for URLs and other unique identifiers.
- Return type:
str
Sync Memory Repositories#
- class advanced_alchemy.repository.memory.SQLAlchemySyncMockRepository(
- *,
- statement=None,
- session,
- model_type=None,
- auto_expunge=False,
- auto_refresh=True,
- auto_commit=False,
- order_by=None,
- error_messages=Empty,
- wrap_exceptions=True,
- load=None,
- execution_options=None,
- uniquify=None,
- **kwargs,
Bases:
ModelRepositoryMixin[ModelT],SQLAlchemySyncRepositoryProtocol[ModelT]In memory repository.
- class advanced_alchemy.repository.memory.SQLAlchemySyncMockSlugRepository#
Bases:
SQLAlchemySyncMockRepository[ModelT],SQLAlchemySyncSlugRepositoryMixin[ModelT],SQLAlchemySyncSlugRepositoryProtocol[ModelT]In-memory repository supporting slug operations.
- get_by_slug(
- slug,
- error_messages=Empty,
- load=None,
- execution_options=None,
- uniquify=None,
- bind_group=None,
- **kwargs,
Select record by slug value.
- Returns:
The model instance or None if not found.
- Return type:
ModelT | None
- get_available_slug(
- value_to_slugify,
- **kwargs,
Get a unique slug for the supplied value.
If the value is found to exist, a random 4 digit character is appended to the end.
Override this method to change the default behavior
- Parameters:
value_to_slugify (
str) – A string that should be converted to a unique slug.**kwargs (Any) – Additional parameters.
- Returns:
a unique slug for the supplied value. This is safe for URLs and other unique identifiers.
- Return type:
str