|
1234567891011121314151617181920212223242526 |
- from sqlalchemy.ext.declarative import declarative_base
- from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
- from sqlalchemy.orm import sessionmaker
- from sqlalchemy.ext.asyncio import AsyncSession
-
- from app.core.config import settings
-
- # Create async engine
- engine = create_async_engine(
- settings.DATABASE_URL,
- pool_pre_ping=True,
- pool_size=10,
- max_overflow=20
- )
-
- # Create a custom session class
- AsyncSessionLocal = sessionmaker(
- engine,
- class_=AsyncSession,
- expire_on_commit=False,
- autocommit=False,
- autoflush=False
- )
-
- # Create a base class for declarative models
- Base = declarative_base()
|