From 12d61e01e1c7652431378c5ed240e044171b89d3 Mon Sep 17 00:00:00 2001 From: Sergey Vanyushkin Date: Sun, 21 Apr 2024 21:02:50 +0000 Subject: [PATCH] sync --- api/application/abstractions/transaction.py | 15 +++++++++++++++ api/infrastructure/persistence/transaction.py | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 api/application/abstractions/transaction.py 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