zhaoqingang
2024-12-04 cdb5f8bf45f117831959291c89e0694606ebb479
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=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