app.database

Database engine, session factory, and the ORM declarative base.

Alembic owns all schema changes; this module never calls Base.metadata.create_all() outside of tests. The SQLAlchemy +psycopg dialect modifier is injected here at engine-construction time so the configured DSN stays a portable, provider-neutral postgresql:// URL.

class app.database.Base(**kwargs)

Bases: DeclarativeBase

Declarative base class for all ORM models.

registry: ClassVar[registry] = <sqlalchemy.orm.decl_api.registry object>

Refers to the _orm.registry in use where new _orm.Mapper objects will be associated.

app.database.get_engine(database_url)

Return a cached SQLAlchemy engine for the given DSN.

Caching keyed by the plain DSN string lets dependency overrides (for example in tests) swap in a different database without reconstructing an engine on every call for the common case.

Parameters:

database_url (str) – Plain postgresql:// DSN.

Return type:

Engine

Returns:

A SQLAlchemy Engine for that DSN.

app.database.get_db(settings=Depends(dependency=<functools._lru_cache_wrapper object>, use_cache=True, scope=None))

Yield one request-scoped database session.

The session is closed in a finally block regardless of whether the request raised an exception.

Parameters:

settings (Settings) – Application settings, injected so tests can override app.config.get_settings() with a different DSN.

Return type:

Generator[Session]

Returns:

A generator yielding a single Session.