The backend component to interface with the smart contract.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

session.py 500 B

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()