Spaces:
Runtime error
Runtime error
Download app/database.py from Corin1998/GrowthOps_OS: direct link, hf CLI and curl.
- Browser
- Download file 700 Bytes
-
https://huggingface.co/spaces/Corin1998/GrowthOps_OS/resolve/main/app/database.py
- Command line
-
hf download hf://spaces/Corin1998/GrowthOps_OS/app/database.py
-
curl -L -o database.py https://huggingface.co/spaces/Corin1998/GrowthOps_OS/resolve/main/app/database.py
700 Bytes
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import sessionmaker, DeclarativeBase | |
| from .config import Settings, build_database_url | |
| settings = Settings() | |
| db_url = build_database_url(settings) | |
| class Base(DeclarativeBase): | |
| pass | |
| engine_kwargs = {"echo": False, "pool_pre_ping": True} | |
| if db_url.startswith("sqlite"): | |
| # Uvicorn / FastAPI でスレッド跨ぎが起きても問題ないように | |
| engine_kwargs["connect_args"] = {"check_same_thread": False} | |
| engine = create_engine(db_url, **engine_kwargs) | |
| SessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False) | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |