22 lines
510 B
Python
22 lines
510 B
Python
import os
|
|
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import declarative_base, sessionmaker
|
|
|
|
|
|
DATABASE_URL = os.getenv(
|
|
"DATABASE_URL", "postgresql+psycopg://exam_user:exam_pass@localhost:5432/exam_helper"
|
|
)
|
|
|
|
engine = create_engine(DATABASE_URL, future=True, pool_pre_ping=True)
|
|
SessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False, future=True)
|
|
Base = declarative_base()
|
|
|
|
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|