Team Ai
Apppublic

kernelmind/Resume-Screener-API

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
database.py46 linesDownload Raw Back to src
1"""2Database configuration for user authentication.3 4Using SQLite for simplicity - easy to set up, no external dependencies.5For production, switch to PostgreSQL with async driver.6"""7 8from sqlalchemy import create_engine9from sqlalchemy.orm import sessionmaker, declarative_base10 11# SQLite database file in project root12DATABASE_URL = "sqlite:///./users.db"13 14# Create engine - check_same_thread=False needed for SQLite + FastAPI15engine = create_engine(16    DATABASE_URL,17    connect_args={"check_same_thread": False}  # SQLite specific18)19 20# Session factory21SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)22 23# Base class for models24Base = declarative_base()25 26 27def get_db():28    """29    Dependency that provides a database session.30    31    Usage:32        @app.get("/users")33        def get_users(db: Session = Depends(get_db)):34            ...35    """36    db = SessionLocal()37    try:38        yield db39    finally:40        db.close()41 42 43def init_db():44    """Create all tables. Called on app startup."""45    Base.metadata.create_all(bind=engine)46