16 lines
434 B
Python
16 lines
434 B
Python
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker, declarative_base
|
|
|
|
DATABASE_URL = "postgresql+psycopg2://postgres:postgres@db:5432/postgres"
|
|
|
|
engine = create_engine(DATABASE_URL, future=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()
|