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:
DeclarativeBaseDeclarative base class for all ORM models.
- 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) – Plainpostgresql://DSN.- Return type:
Engine- Returns:
A SQLAlchemy
Enginefor 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
finallyblock regardless of whether the request raised an exception.- Parameters:
settings (
Settings) – Application settings, injected so tests can overrideapp.config.get_settings()with a different DSN.- Return type:
Generator[Session]- Returns:
A generator yielding a single
Session.