Files
xiaoxia-saas/apps/api/app/db.py
T
Xiaoxia AI b06201e503
Deploy / Deploy Staging (push) Failing after 6s
Deploy / Deploy Production (push) Has been skipped
Tests / test (push) Failing after 16s
Tests / lint (push) Failing after 16s
fix(phase7): align api runtime wiring for integration
2026-06-17 18:48:08 +08:00

25 lines
692 B
Python

from collections.abc import Generator
from sqlalchemy.orm import Session
from app.config import settings
from packages.adapters.sqlalchemy_impl import build_session_factory, ensure_database_exists, initialize_database
ensure_database_exists(settings.DATABASE_URL)
engine, SessionLocal = build_session_factory(
settings.DATABASE_URL,
pool_size=settings.DATABASE_POOL_SIZE,
max_overflow=settings.DATABASE_MAX_OVERFLOW,
pool_timeout=settings.DATABASE_POOL_TIMEOUT,
pool_recycle=settings.DATABASE_POOL_RECYCLE,
)
initialize_database(engine)
def get_db() -> Generator[Session, None, None]:
db = SessionLocal()
try:
yield db
finally:
db.close()