Session Backends¶
This module provides SQLAlchemy-based session backends for Litestar’s server-side session middleware.
Session Model Mixin¶
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 SessionModelMixin
- __deepcopy__(memo)[source]¶
Custom deepcopy implementation to handle unpicklable SQLAlchemy objects.
- Return type:
SQLAlchemySessionBackendBase
[TypeVar
(SQLAlchemyConfigT
, bound=Union
[SQLAlchemyAsyncConfig
,SQLAlchemySyncConfig
])]
- 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
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