Spaces:
Sleeping
Sleeping
Download app/database.py from AP314159/attendance: direct link, hf CLI and curl.
- Browser
- Download file 641 Bytes
-
https://huggingface.co/spaces/AP314159/attendance/resolve/main/app/database.py
- Command line
-
hf download hf://spaces/AP314159/attendance/app/database.py
-
curl -L -o database.py https://huggingface.co/spaces/AP314159/attendance/resolve/main/app/database.py
641 Bytes
| from sqlalchemy import create_engine | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from sqlalchemy.orm import sessionmaker | |
| import redis | |
| from .settings import settings | |
| # PostgreSQL Setup | |
| engine = create_engine(settings.database_url) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |
| # Redis Setup | |
| redis_client = redis.from_url(settings.redis_url, decode_responses=True) | |
| # Dependency to get a DB session | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |
| # Dependency to get a Redis client | |
| def get_redis(): | |
| return redis_client | |