asyncsession.py 594 B

1234567891011121314151617
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
  4. from sqlalchemy.orm import sessionmaker
  5. from core.config import settings
  6. async_engine = create_async_engine(settings.ASYNC_MYSQL_URI,
  7. echo=True,
  8. pool_size=50,
  9. max_overflow=20,
  10. pool_pre_ping=True)
  11. LocalAsyncSession = sessionmaker(class_=AsyncSession, autocommit=False, bind=async_engine)
  12. __all__ = ["async_engine", "LocalAsyncSession"]