asyncsession.py 648 B

12345678910111213141516171819
  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. pool_size=30,
  8. max_overflow=20,
  9. pool_pre_ping=True)
  10. LocalAsyncSession = sessionmaker(class_=AsyncSession,
  11. autocommit=False,
  12. autoflush=False,
  13. bind=async_engine)
  14. __all__ = ["LocalAsyncSession"]