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:
__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:
get_engine() sqlalchemy.engine.Engine[source]

Retrieve the SQLAlchemy engine from the app context.

Returns:

The SQLAlchemy engine.

Return type:

EngineT

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.

Parameters:

request (sanic.Request) – The incoming request.

Returns:

The session associated with the request.

Return type:

SessionT

get_engine_from_request(request: sanic.Request) sqlalchemy.engine.Engine[source]

Retrieve the engine from the request context.

Parameters:

request (sanic.Request) – The incoming request.

Returns:

The SQLAlchemy engine.

Return type:

EngineT

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:

SessionMakerT

get_session_from_request(request: sanic.Request) sqlalchemy.orm.Session[source]

Retrieve the session from the request context.

Parameters:

request (sanic.Request) – The incoming request.

Returns:

The session associated with the request.

Return type:

SessionT

startup(bootstrap: Extend) None[source]

Advanced Alchemy Sanic extension startup hook.

Parameters:

bootstrap (sanic_ext.Extend) – The Sanic extension bootstrap.