from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker from .config import settings # Create engine if settings.DATABASE_URL.startswith("sqlite"): engine = create_engine( settings.DATABASE_URL, connect_args={"check_same_thread": False} ) else: engine = create_engine(settings.DATABASE_URL) # Create session SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) # Base class for models Base = declarative_base() # Dependency to get database session def get_db(): db = SessionLocal() try: yield db finally: db.close()