| """ | |
| DRP Backend — Database Configuration | |
| SQLite + SQLAlchemy for the prototype. | |
| """ | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import sessionmaker, declarative_base | |
| DATABASE_URL = "sqlite:///./drp.db" | |
| engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False}) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |
| def get_db(): | |
| """Dependency for FastAPI routes — yields a DB session.""" | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |
| def init_db(): | |
| """Create all tables. Called once on startup.""" | |
| from models import Base as _ # noqa: ensure models are imported | |
| Base.metadata.create_all(bind=engine) | |