Spaces:
Runtime error
Runtime error
Download app/db.py from RamshaAnwar/contextquery-api: direct link, hf CLI and curl.
- Browser
- Download file 487 Bytes
-
https://huggingface.co/spaces/RamshaAnwar/contextquery-api/resolve/main/app/db.py
- Command line
-
hf download hf://spaces/RamshaAnwar/contextquery-api/app/db.py
-
curl -L -o db.py https://huggingface.co/spaces/RamshaAnwar/contextquery-api/resolve/main/app/db.py
487 Bytes
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import sessionmaker, declarative_base | |
| from app.config import settings | |
| engine = create_engine( | |
| settings.DATABASE_URL, | |
| pool_pre_ping=True, | |
| pool_size=3, | |
| max_overflow=2, | |
| connect_args={"prepare_threshold": None} | |
| ) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() |