zhaoqingang
2024-11-28 5580958d49e5aab48908000614e47ecb75ff4797
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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=True)
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