Spaces:
Running
Running
| from typing import Generator | |
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import sessionmaker | |
| from dotenv import load_dotenv | |
| import os | |
| load_dotenv() | |
| DATABASE_URL = os.getenv("DATABASE_URL") | |
| engine = create_engine(DATABASE_URL) | |
| SessionLocal = sessionmaker(bind=engine) | |
| def get_session() -> Generator: | |
| """ | |
| Get a connection to the Postgres database | |
| """ | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |