Session Backends¶
This module provides SQLAlchemy-based session backends for Litestar’s server-side session middleware.
Session Model Mixin¶
- class advanced_alchemy.extensions.litestar.session.SessionModelMixin[source]¶
Bases:
UUIDv7BaseMixin for session storage.
- is_expired¶
SQL-Expression to check if the session has expired.
- Returns:
SQL-Expression to check if the session has expired.
Session Backend Base¶
- class advanced_alchemy.extensions.litestar.session.SQLAlchemySessionBackendBase[source]¶
Bases:
ServerSideSessionBackend,ABC,Generic[SQLAlchemyConfigT]Session backend to store data in a database with SQLAlchemy. Works with both sync and async engines.
Notes
Requires sqlalchemy which needs to be installed separately, and a configured SQLAlchemyPlugin.
- __init__(config, alchemy_config, model)[source]¶
Initialize BaseSQLAlchemyBackend.
- Parameters:
config¶ (
ServerSideSessionConfig) – An instance of SQLAlchemyBackendConfigalchemy_config¶ (
TypeVar(SQLAlchemyConfigT, bound=Union[SQLAlchemyAsyncConfig,SQLAlchemySyncConfig])) – An instance of SQLAlchemyConfigmodel¶ (
type[SessionModelMixin]) – A mapped model subclassing SessionModelMixinconfig (ServerSideSessionConfig)
alchemy_config (SQLAlchemyConfigT)
model (type[SessionModelMixin])
- Return type:
None
- __deepcopy__(memo)[source]¶
Custom deepcopy implementation to handle unpicklable SQLAlchemy objects.
- Return type:
SQLAlchemySessionBackendBase[TypeVar(SQLAlchemyConfigT, bound=Union[SQLAlchemyAsyncConfig,SQLAlchemySyncConfig])]- Parameters:
- static supports_merge(dialect=None, force_disable_merge=False)[source]¶
Check if the dialect supports MERGE statements for upserts.
Async Session Backend¶
- class advanced_alchemy.extensions.litestar.session.SQLAlchemyAsyncSessionBackend[source]¶
Bases:
SQLAlchemySessionBackendBase[SQLAlchemyAsyncConfig]Asynchronous SQLAlchemy backend.
- async set(session_id, data, store)[source]¶
Store data under the session_id for later retrieval.
If there is already data associated with session_id, replace it with data and reset its expiry time
- async delete(session_id, store)[source]¶
Delete the data associated with session_id. Fails silently if no such session-ID exists.
Sync Session Backend¶
- class advanced_alchemy.extensions.litestar.session.SQLAlchemySyncSessionBackend[source]¶
Bases:
SQLAlchemySessionBackendBase[SQLAlchemySyncConfig]Synchronous SQLAlchemy backend.
- async set(session_id, data, store)[source]¶
Store data under the session_id for later retrieval.
If there is already data associated with session_id, replace it with data and reset its expiry time