Spaces:
No application file
No application file
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import sessionmaker | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from app.config import settings | |
| # Use NEON_DATABASE_URL if available, otherwise fall back to DATABASE_URL | |
| SQLALCHEMY_DATABASE_URL = settings.NEON_DATABASE_URL or settings.DATABASE_URL or "sqlite:///./test.db" | |
| engine = create_engine(SQLALCHEMY_DATABASE_URL) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |