Spaces:
Running
Running
Download app/modules/session.py from Dama12/scientific-backend: direct link, hf CLI and curl.
- Browser
- Download file 652 Bytes
-
https://huggingface.co/spaces/Dama12/scientific-backend/resolve/main/app/modules/session.py
- Command line
-
hf download hf://spaces/Dama12/scientific-backend/app/modules/session.py
-
curl -L -o session.py https://huggingface.co/spaces/Dama12/scientific-backend/resolve/main/app/modules/session.py
652 Bytes
| """ | |
| SQLAlchemy session configuration | |
| """ | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import sessionmaker, Session | |
| from typing import Generator | |
| from app.core.settings import settings | |
| # Create engine | |
| engine = create_engine( | |
| settings.DATABASE_URL, | |
| echo=settings.DB_ECHO, | |
| pool_pre_ping=True, | |
| pool_size=10, | |
| max_overflow=20 | |
| ) | |
| # Create session factory | |
| SessionLocal = sessionmaker( | |
| autocommit=False, | |
| autoflush=False, | |
| bind=engine | |
| ) | |
| def get_db() -> Generator[Session, None, None]: | |
| """Dependency pour obtenir une session DB""" | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |