Spaces:
Runtime error
Runtime error
Download database.py from Hackez2/machathon-ocr: direct link, hf CLI and curl.
- Browser
- Download file 576 Bytes
-
https://huggingface.co/spaces/Hackez2/machathon-ocr/resolve/main/database.py
- Command line
-
hf download hf://spaces/Hackez2/machathon-ocr/database.py
-
curl -L -o database.py https://huggingface.co/spaces/Hackez2/machathon-ocr/resolve/main/database.py
576 Bytes
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import sessionmaker, declarative_base | |
| from config import DATABASE_URL | |
| engine = create_engine(DATABASE_URL, pool_pre_ping=True) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |
| def get_db(): | |
| """FastAPI dependency that yields a DB session and closes it after use.""" | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |
| def init_db(): | |
| """Create all tables. Called once at startup.""" | |
| Base.metadata.create_all(bind=engine) | |