import os from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker from app.config.config import settings DATABASE_URL = os.getenv('POSTGRESQL_DATABASE_URL') or settings.postgresql_database_url engine = create_async_engine(DATABASE_URL, echo=False) PostgresqlSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine, class_=AsyncSession) PostgresqlBase = declarative_base() async def get_pdb() -> AsyncSession: async with PostgresqlSessionLocal() as session: # yield session try: yield session finally: session.close()