sanic¶
Note
More details soon
- class advanced_alchemy.extensions.sanic.CommitStrategyExecutor[source]¶
Bases:
Protocol
- __init__(*args, **kwargs)¶
- class advanced_alchemy.extensions.sanic.SanicAdvancedAlchemy[source]¶
Bases:
Generic
[EngineT
,SessionT
,SessionMakerT
],Extension
Sanic extension for integrating Advanced Alchemy with SQLAlchemy.
- Parameters:
sqlalchemy_config¶ (advanced_alchemy.config.sync.SQLAlchemySyncConfig | advanced_alchemy.config.asyncio.SQLAlchemyAsyncConfig) – Configuration for SQLAlchemy.
autocommit¶ (advanced_alchemy.config.types.CommitStrategy | None) – Strategy for committing transactions. Defaults to None.
counters¶ (sanic.helpers.Default | bool | None) – Enables or disables counters. Defaults to sanic.helpers._default.
session_maker_key¶ (str| None) – Key for the session maker in app context. Defaults to “sessionmaker”.
engine_key¶ (str| None) – Key for the engine in app context. Defaults to “engine”.
session_key¶ (str| None) – Key for the session in request context. Defaults to “session”.
- __init__(*, sqlalchemy_config: SQLAlchemyAsyncConfig, autocommit: CommitStrategy | None = None, counters: Default | bool = _default, session_maker_key: str = 'sessionmaker', engine_key: str = 'engine', session_key: str = 'session') None [source]¶
- __init__(*, sqlalchemy_config: SQLAlchemySyncConfig, autocommit: CommitStrategy | None = None, counters: Default | bool = _default, session_maker_key: str = 'sessionmaker', engine_key: str = 'engine', session_key: str = 'session') None
- async session_handler(session: Session | AsyncSession, request: Request, response: HTTPResponse) None [source]¶
Handle the session lifecycle based on the commit strategy.
- Parameters:
session¶ (sqlalchemy.orm.Session | sqlalchemy.ext.asyncio.AsyncSession) – The current session.
request¶ (sanic.Request) – The incoming request.
response¶ (sanic.HTTPResponse) – The outgoing response.
- get_engine() sqlalchemy.engine.Engine [source]¶
Retrieve the SQLAlchemy engine from the app context.
- Returns:
The SQLAlchemy engine.
- Return type:
- get_sessionmaker() Callable[[], sqlalchemy.orm.Session] [source]¶
Retrieve the session maker.
- Returns:
A callable that returns a new session.
- Return type:
Callable[[], SessionT]
- get_session(request: sanic.Request) sqlalchemy.orm.Session [source]¶
Retrieve or create a session for the current request.
- get_engine_from_request(request: sanic.Request) sqlalchemy.engine.Engine [source]¶
Retrieve the engine from the request context.
- get_sessionmaker_from_request(request: sanic.Request) SessionMakerT [source]¶
Retrieve the session maker from the request context.
- Parameters:
request¶ (sanic.Request) – The incoming request.
- Returns:
The session maker.
- Return type:
- get_session_from_request(request: sanic.Request) sqlalchemy.orm.Session [source]¶
Retrieve the session from the request context.