27 lines
461 B
Python
27 lines
461 B
Python
from sqlalchemy.ext.asyncio import (
|
|
AsyncSession,
|
|
async_sessionmaker,
|
|
create_async_engine,
|
|
)
|
|
from sqlalchemy.orm import DeclarativeBase
|
|
|
|
from .config import DB_URL
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
engine = create_async_engine(DB_URL, echo=True)
|
|
|
|
SessionLocal = async_sessionmaker(
|
|
bind=engine,
|
|
expire_on_commit=False,
|
|
class_=AsyncSession,
|
|
)
|
|
|
|
|
|
async def get_db():
|
|
async with SessionLocal() as session:
|
|
yield session
|