Skip to content

sqlalchemy_plugin

Database connectivity and transaction management for the application.

async_session_factory module-attribute

async_session_factory: async_sessionmaker[AsyncSession] = async_sessionmaker(engine)

Database session factory. See async_sessionmaker().

engine module-attribute

engine = create_async_engine(
    settings.db.URL,
    echo=settings.db.ECHO,
    echo_pool=settings.db.ECHO_POOL,
    json_serializer=partial(dumps, default=_default),
    max_overflow=settings.db.POOL_MAX_OVERFLOW,
    pool_size=settings.db.POOL_SIZE,
    pool_timeout=settings.db.POOL_TIMEOUT,
    poolclass=NullPool if settings.db.POOL_DISABLE else None,
)

Configure via DatabaseSettings. Overrides default JSON serializer to use orjson. See create_async_engine() for detailed instructions.

before_send_handler async

before_send_handler(message, _, scope)

Custom before_send_handler for SQLAlchemy plugin that inspects the status of response and commits, or rolls back the database.

Parameters:

Name Type Description Default
message Message

ASGI message

required
_ State required
scope Scope

ASGI scope

required