Spaces:
Sleeping
Sleeping
Download backend/database/connection.py from ashutoshneemval/CLAT_Guide: direct link, hf CLI and curl.
- Browser
- Download file 717 Bytes
-
https://huggingface.co/spaces/ashutoshneemval/CLAT_Guide/resolve/main/backend/database/connection.py
- Command line
-
hf download hf://spaces/ashutoshneemval/CLAT_Guide/backend/database/connection.py
-
curl -L -o connection.py https://huggingface.co/spaces/ashutoshneemval/CLAT_Guide/resolve/main/backend/database/connection.py
717 Bytes
| from sqlalchemy import create_engine | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from sqlalchemy.orm import sessionmaker | |
| from config import settings | |
| # If using SQLite, we need connect_args to allow access from multiple threads (FastAPI async) | |
| if settings.DATABASE_URL.startswith("sqlite"): | |
| engine = create_engine( | |
| settings.DATABASE_URL, | |
| connect_args={"check_same_thread": False} | |
| ) | |
| else: | |
| engine = create_engine( | |
| settings.DATABASE_URL, | |
| pool_pre_ping=True | |
| ) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |