Spaces:
Runtime error
Runtime error
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import declarative_base, sessionmaker | |
| from backend.app.config import settings | |
| # Check if using SQLite to add thread compatibility | |
| connect_args = {} | |
| if settings.DATABASE_URL.startswith("sqlite"): | |
| connect_args = {"check_same_thread": False} | |
| engine = create_engine( | |
| settings.DATABASE_URL, | |
| connect_args=connect_args, | |
| pool_pre_ping=True | |
| ) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |