21 lines
501 B
Python
21 lines
501 B
Python
from sqlalchemy import create_engine
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
from app.config import config
|
|
|
|
DATABASE_URL = f"postgresql://{config['DB_USERNAME']}:{config['DB_PASSWORD']}@{config['DB_HOST']}/{config['DB_NAME']}"
|
|
|
|
engine = create_engine(DATABASE_URL)
|
|
|
|
session_factory = sessionmaker(bind=engine)
|
|
|
|
EntityBase = declarative_base()
|
|
|
|
|
|
def get_db():
|
|
db = session_factory()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|