uow and di basic implementation
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
from sqlalchemy import insert, select
|
||||
@@ -9,17 +8,7 @@ import api.models as models
|
||||
ModelType = TypeVar("ModelType", bound=models.Base)
|
||||
|
||||
|
||||
class AbstractRepository(ABC):
|
||||
@abstractmethod
|
||||
async def add_one(self, data: dict):
|
||||
raise NotImplementedError()
|
||||
|
||||
@abstractmethod
|
||||
async def find_all(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class SQLAlchemyRepository(AbstractRepository, Generic[ModelType]):
|
||||
class SQLAlchemyRepository(Generic[ModelType]):
|
||||
model: type[ModelType]
|
||||
|
||||
def __init__(self, session: AsyncSession):
|
||||
|
@@ -1,32 +1,6 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from api.repository.user import UserRepository
|
||||
|
||||
|
||||
class IUnitOfWork(ABC):
|
||||
users: type[UserRepository]
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
...
|
||||
|
||||
@abstractmethod
|
||||
async def __aenter__(self):
|
||||
...
|
||||
|
||||
@abstractmethod
|
||||
async def __aexit__(self):
|
||||
...
|
||||
|
||||
@abstractmethod
|
||||
async def commit(self):
|
||||
...
|
||||
|
||||
@abstractmethod
|
||||
async def rollback(self):
|
||||
...
|
||||
|
||||
|
||||
class UnitOfWork:
|
||||
def __init__(self, session_factory):
|
||||
self.session_factory = session_factory
|
||||
|
Reference in New Issue
Block a user