20 lines
408 B
Python
20 lines
408 B
Python
|
|
from sqlalchemy import create_engine
|
||
|
|
from sqlalchemy.orm import sessionmaker, DeclarativeBase
|
||
|
|
|
||
|
|
from web.config import settings
|
||
|
|
|
||
|
|
engine = create_engine(settings.DATABASE_URL, pool_pre_ping=True)
|
||
|
|
SessionLocal = sessionmaker(bind=engine, autocommit=False, autoflush=False)
|
||
|
|
|
||
|
|
|
||
|
|
class Base(DeclarativeBase):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
def get_db():
|
||
|
|
db = SessionLocal()
|
||
|
|
try:
|
||
|
|
yield db
|
||
|
|
finally:
|
||
|
|
db.close()
|