vinindkoeb/app/db.py
carsten 589dcbcdf5 Scaffold FastAPI + SQLModel + Alembic project, Postgres-backed
Config-driven DATABASE_URL shared by the app and Alembic's env.py
(fixes v1's config drift), psycopg3 driver, auto-discovering
app/models package for SQLModel.metadata, and a /health endpoint
that exercises the DB dependency end-to-end.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-27 15:57:44 +02:00

23 lines
505 B
Python

from collections.abc import Generator
from typing import Annotated
from fastapi import Depends
from sqlmodel import Session, create_engine
from app.core.config import get_settings
settings = get_settings()
engine = create_engine(
settings.database_url,
echo=settings.environment == "development",
pool_pre_ping=True,
)
def get_session() -> Generator[Session, None, None]:
with Session(engine) as session:
yield session
SessionDep = Annotated[Session, Depends(get_session)]