CRUD names the four basic data-management actions: create, read, update, and delete. A repository interface can make these operations explicit while allowing the underlying storage to change. section 4.3.3
A practical implementation starts with an in-memory list of assets. This supports an end-to-end test before replacing temporary storage with PostgreSQL, while keeping the business domain insulated behind repository ports. section 4.3.3
A generic repository typically exposes these operations:
- create(entity): add a new entity. section 4.3.3
- read(entity_id): retrieve an entity by identifier. section 4.3.3
- update(entity): replace an existing entity. section 4.3.3
- delete(entity_id): remove an entity by identifier. section 4.3.3
Listing 4.26 Code for BaseRepository, our generic data access layer
from abc import ABC, abstractmethod
from typing import List, TypeVar, Generic
T = TypeVar('T')
class BaseRepository(ABC, Generic[T]):
@abstractmethod
def create(self, entity: T) -> None:
pass
@abstractmethod
def read(self, entity_id: int) -> T:
pass
@abstractmethod
def update(self, entity: T) -> None:
pass
@abstractmethod
def delete(self, entity_id: int) -> None:
pass
@abstractmethod
def get_entities(self) -> List[T]:
pass
Shows a typed Python BaseRepository abstract class whose contract includes create, read, update, delete, and entity-listing methods. section 4.3.3
Assets with an in-memory repository
InMemoryAssetRepository stores Asset objects in a list, appends on create, searches by id on read, replaces matching objects on update, and filters matching objects out on delete. AssetManager delegates its asset operations to this repository. section 4.3.3










