diff --git a/api/application/abstractions/transaction.py b/api/application/abstractions/transaction.py new file mode 100644 index 0000000..9af0639 --- /dev/null +++ b/api/application/abstractions/transaction.py @@ -0,0 +1,15 @@ +from typing import Protocol + + +class TransactionContextManager(Protocol): + async def __aenter__(self): + raise NotImplementedError + + async def __aexit__(self, exc_type, exc_val, exc_tb): + raise NotImplementedError + + async def commit(self): + raise NotImplementedError + + async def rollback(self): + raise NotImplementedError diff --git a/api/infrastructure/persistence/transaction.py b/api/infrastructure/persistence/transaction.py index 4064266..bab0393 100644 --- a/api/infrastructure/persistence/transaction.py +++ b/api/infrastructure/persistence/transaction.py @@ -2,10 +2,11 @@ from types import TracebackType from sqlalchemy.ext.asyncio import AsyncSession +from api.application.abstractions.transaction import TransactionContextManager from api.infrastructure.persistence.error import TransactionContextManagerError -class SqlalchemyTransactionContextManager: +class SqlalchemyTransactionContextManager(TransactionContextManager): def __init__(self, session: AsyncSession): self._session = session