Spaces:
Sleeping
Sleeping
Download app/db/database.py from thabsheeeeeer/DocBrain-API: direct link, hf CLI and curl.
- Browser
- Download file 529 Bytes
-
https://huggingface.co/spaces/thabsheeeeeer/DocBrain-API/resolve/main/app/db/database.py
- Command line
-
hf download hf://spaces/thabsheeeeeer/DocBrain-API/app/db/database.py
-
curl -L -o database.py https://huggingface.co/spaces/thabsheeeeeer/DocBrain-API/resolve/main/app/db/database.py
529 Bytes
| import os | |
| from dotenv import load_dotenv | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import sessionmaker, declarative_base | |
| load_dotenv() | |
| DATABASE_URL = os.getenv("DATABASE_URL") | |
| if not DATABASE_URL: | |
| raise ValueError("DATABASE_URL is missing in .env file") | |
| engine = create_engine(DATABASE_URL) | |
| SessionLocal = sessionmaker( | |
| autocommit=False, | |
| autoflush=False, | |
| bind=engine | |
| ) | |
| Base = declarative_base() | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() |