Files
eamco_playground/database.py
2026-01-18 19:04:21 -05:00

34 lines
756 B
Python

from sqlalchemy import create_engine
from sqlalchemy.engine import URL
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import declarative_base
from config import load_config
ApplicationConfig = load_config()
url = URL.create(
drivername="postgresql",
username=ApplicationConfig.POSTGRES_USERNAME,
password=ApplicationConfig.POSTGRES_PW,
host=ApplicationConfig.POSTGRES_SERVER,
database=ApplicationConfig.POSTGRES_DBNAME00,
port=ApplicationConfig.POSTGRES_PORT
)
engine = create_engine(url)
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
Base.metadata.create_all(engine)
def get_db():
db = Session()
try:
yield db
finally:
db.close()