Store#
This module provides a SQLAlchemy-backed implementation of Litestar’s
Store protocol. Register a
SQLAlchemyStore under the "sessions" store name to back Litestar’s
server-side session middleware with your SQLAlchemy database.
Store Model Mixin#
SQLAlchemy Store#
- class advanced_alchemy.extensions.litestar.store.SQLAlchemyStore[source]#
Bases:
NamespacedStore,Generic[SQLAlchemyConfigT]SQLAlchemy based, thread and process safe asynchronous key/value store.
Supports both synchronous and asynchronous SQLAlchemy configurations.
- __init__(config, model=StoreModelMixin, namespace=Empty)[source]#
Initialize
SQLAlchemyStore.- Parameters:
config¶ – An instance of
SQLAlchemyAsyncConfigorSQLAlchemySyncConfig.model¶ – The SQLAlchemy model to use for storing data. Defaults to
StoreItem.namespace¶ – A virtual namespace for keys. If not given, defaults to
LITESTAR. Namespacing can be explicitly disabled by passingNone. This will makedelete_all()anddelete_expired()unavailable.
- async delete_all()[source]#
Delete all values in the namespace. Handles both sync and async backends.
- async delete_expired()[source]#
Delete expired values in this namespace using either a sync or async backend.
Values expiring at or before the current time are deleted. Values without an expiration time and values in other namespaces are preserved. Call this method periodically to reclaim storage; expired values are otherwise only hidden by reads.
- Raises:
ImproperlyConfiguredException – If no namespace is configured.
- Return type:
- with_namespace(namespace)[source]#
Return a new
SQLAlchemyStorewith a nested virtual key namespace.- Return type:
SQLAlchemyStore[TypeVar(SQLAlchemyConfigT, bound=Union[SQLAlchemyAsyncConfig,SQLAlchemySyncConfig])]- Parameters:
namespace (str)