Spaces:
Configuration error
Configuration error
Download app/database.py from Taimwe/trainhub-api: direct link, hf CLI and curl.
- Browser
- Download file 549 Bytes
-
https://huggingface.co/spaces/Taimwe/trainhub-api/resolve/main/app/database.py
- Command line
-
hf download hf://spaces/Taimwe/trainhub-api/app/database.py
-
curl -L -o database.py https://huggingface.co/spaces/Taimwe/trainhub-api/resolve/main/app/database.py
549 Bytes
| """SQLAlchemy engine, session factory and declarative base.""" | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import sessionmaker, declarative_base | |
| from .config import DATABASE_URL | |
| _connect_args = {"check_same_thread": False} if DATABASE_URL.startswith("sqlite") else {} | |
| engine = create_engine(DATABASE_URL, connect_args=_connect_args) | |
| SessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False) | |
| Base = declarative_base() | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |