Download app/core/database.py from Noor2623/Smart-Query-Routing-Email-Automation-System: direct link, hf CLI and curl.
- Browser
- Download file 557 Bytes
-
https://huggingface.co/spaces/Noor2623/Smart-Query-Routing-Email-Automation-System/resolve/main/app/core/database.py
- Command line
-
hf download hf://spaces/Noor2623/Smart-Query-Routing-Email-Automation-System/app/core/database.py
-
curl -L -o database.py https://huggingface.co/spaces/Noor2623/Smart-Query-Routing-Email-Automation-System/resolve/main/app/core/database.py
557 Bytes
| from collections.abc import Generator | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import declarative_base, sessionmaker | |
| from app.config import settings | |
| if not settings.database_url: | |
| raise RuntimeError("DATABASE_URL is not set") | |
| engine = create_engine( | |
| settings.database_url, | |
| pool_pre_ping=True, | |
| ) | |
| SessionLocal = sessionmaker( | |
| autocommit=False, | |
| autoflush=False, | |
| bind=engine, | |
| ) | |
| Base = declarative_base() | |
| def get_db() -> Generator: | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |