Add server/db.py
This commit is contained in:
13
server/db.py
Normal file
13
server/db.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
|
||||||
|
from sqlalchemy.orm import sessionmaker, declarative_base
|
||||||
|
|
||||||
|
DATABASE_URL = "postgresql+asyncpg://weather_user:weather_pass@db:5432/weather"
|
||||||
|
|
||||||
|
engine = create_async_engine(DATABASE_URL, echo=False)
|
||||||
|
AsyncSessionLocal = sessionmaker(bind=engine, class_=AsyncSession, expire_on_commit=False)
|
||||||
|
|
||||||
|
Base = declarative_base()
|
||||||
|
|
||||||
|
async def get_session():
|
||||||
|
async with AsyncSessionLocal() as session:
|
||||||
|
yield session
|
Reference in New Issue
Block a user