15 lines
594 B
Python
15 lines
594 B
Python
|
|
from sqlalchemy import create_engine
|
||
|
|
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
|
||
|
|
from sqlalchemy.orm import sessionmaker, declarative_base
|
||
|
|
from contextlib import contextmanager
|
||
|
|
|
||
|
|
# database.py
|
||
|
|
DATABASE_URL = "postgresql+asyncpg://fatura:102030@ic-postgresql-FtOY:5432/producao"
|
||
|
|
|
||
|
|
async_engine = create_async_engine(DATABASE_URL, echo=False, future=True)
|
||
|
|
AsyncSessionLocal = sessionmaker(bind=async_engine, class_=AsyncSession, expire_on_commit=False)
|
||
|
|
Base = declarative_base()
|
||
|
|
|
||
|
|
async def get_session():
|
||
|
|
async with AsyncSessionLocal() as session:
|
||
|
|
yield session
|