Spaces:
Sleeping
Sleeping
Download Backend/app/database.py from orakzai-io/Async_Web_scraper: direct link, hf CLI and curl.
- Browser
- Download file 640 Bytes
-
https://huggingface.co/spaces/orakzai-io/Async_Web_scraper/resolve/main/Backend/app/database.py
- Command line
-
hf download hf://spaces/orakzai-io/Async_Web_scraper/Backend/app/database.py
-
curl -L -o database.py https://huggingface.co/spaces/orakzai-io/Async_Web_scraper/resolve/main/Backend/app/database.py
640 Bytes
| import os | |
| from dotenv import load_dotenv | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import sessionmaker | |
| # Load environment variables | |
| load_dotenv() | |
| # Database Configuration | |
| DATABASE_URL = os.getenv("DATABASE_URL") | |
| # Create Engine | |
| engine = create_engine(DATABASE_URL, pool_size=30, max_overflow=60, pool_timeout=60) | |
| # Session Factory | |
| SessionLocal = sessionmaker( | |
| autocommit=False, autoflush=False, expire_on_commit=False, bind=engine | |
| ) | |
| # --- DEPENDENCIES --- | |
| # Dependency to get DB session | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |