Download app/database.py from trtlbby/skrep: direct link, hf CLI and curl.
- Browser
- Download file 606 Bytes
-
https://huggingface.co/spaces/trtlbby/skrep/resolve/main/app/database.py
- Command line
-
hf download hf://spaces/trtlbby/skrep/app/database.py
-
curl -L -o database.py https://huggingface.co/spaces/trtlbby/skrep/resolve/main/app/database.py
606 Bytes
| import os | |
| from typing import Generator | |
| from dotenv import load_dotenv | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import declarative_base, sessionmaker | |
| load_dotenv() | |
| DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./data/oer_poc.db") | |
| engine = create_engine( | |
| DATABASE_URL, | |
| connect_args={"check_same_thread": False} if DATABASE_URL.startswith("sqlite") else {}, | |
| ) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |
| def get_db() -> Generator: | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |