The backend component to interface with the smart contract.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

2 个月前
1234567891011121314151617
  1. from typing import AsyncGenerator
  2. from sqlalchemy.exc import SQLAlchemyError
  3. from sqlalchemy.ext.asyncio import AsyncSession
  4. from app.db.base import AsyncSessionLocal
  5. async def get_db_session() -> AsyncGenerator[AsyncSession, None]:
  6. async with AsyncSessionLocal() as session:
  7. try:
  8. yield session
  9. await session.commit()
  10. except SQLAlchemyError as e:
  11. await session.rollback()
  12. raise
  13. finally:
  14. await session.close()