Spaces:
Sleeping
Sleeping
from sqlalchemy import create_engine | |
from sqlalchemy.orm import sessionmaker | |
from models import Base | |
SQLALCHEMY_DATABASE_URL = "sqlite:///database.db" | |
engine = create_engine(SQLALCHEMY_DATABASE_URL) | |
Base.metadata.create_all(engine) | |
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
def get_db(): | |
db = SessionLocal() | |
try: | |
yield db | |
finally: | |
db.close() |