2025-05-17 22:13:56 +00:00

25 lines
615 B
Python

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from app.core.config import settings
# Create the DB directory if it doesn't exist
settings.DB_DIR.mkdir(parents=True, exist_ok=True)
# SQLite connection engine
engine = create_engine(
settings.SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False}
)
# Create a sessionmaker with a class
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
def get_db():
"""Dependency for getting a database session."""
db = SessionLocal()
try:
yield db
finally:
db.close()