from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from app.core.config import settings # Create an engine for the database engine = create_engine( settings.SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}, # Needed for SQLite ) # Create a SessionLocal class for session creation SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) # Dependency to get the database session def get_db(): db = SessionLocal() try: yield db finally: db.close()