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.
Session Backend Base#
- class advanced_alchemy.extensions.litestar.session.SQLAlchemySessionBackendBase(config, alchemy_config, model)[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.
- static supports_merge(
- dialect=None,
- force_disable_merge=False,
Check if the dialect supports MERGE statements for upserts.
- Return type:
bool
Async Session Backend#
- class advanced_alchemy.extensions.litestar.session.SQLAlchemyAsyncSessionBackend[source]#
Bases:
SQLAlchemySessionBackendBase[SQLAlchemyAsyncConfig]Asynchronous SQLAlchemy backend.
- async get(session_id, store)[source]#
Retrieve data associated with session_id.
- Parameters:
session_id (str) – The session-ID
store (Store) – The store to get the session from (not used in this backend)
- Returns:
The session data, if existing, otherwise None.
- Return type:
bytes | None
- 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
- Parameters:
session_id (str) – The session-ID.
data (bytes) – Serialized session data
store (Store) – The store to store the session in (not used in this backend)
Sync Session Backend#
- class advanced_alchemy.extensions.litestar.session.SQLAlchemySyncSessionBackend[source]#
Bases:
SQLAlchemySessionBackendBase[SQLAlchemySyncConfig]Synchronous SQLAlchemy backend.
- async get(session_id, store)[source]#
Retrieve data associated with session_id.
- Parameters:
session_id (str) – The session-ID
store (Store) – The store to get the session from
- Returns:
The session data, if existing, otherwise None.
- Return type:
bytes | None
- 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
- Parameters:
session_id (str) – The session-ID
data (bytes) – Serialized session data
store (Store) – The store to store the session in