In Memory Write Repository¶
in_memory_write_repository
¶
Write-only repository backed by an in-memory dictionary.
Stores entities keyed by identifier, supporting insert, update, and
delete operations with optimistic concurrency via etag versioning.
InMemoryWriteRepository
¶
Bases: WriteOnlyRepositoryPort[TEntity, TId]
In-memory write-only repository backed by a dictionary.
Stores entities in a dictionary keyed by their identifier.
The storage mapping is injected via the constructor and copied on init
to ensure independence from external mutation.
Example
Source code in src/forging_blocks/infrastructure/repositories/in_memory_write_repository.py
__init__(storage: Mapping[TId, TEntity] | None = None) -> None
¶
Initialize the write repository with optional external storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storage
|
Mapping[TId, TEntity] | None
|
An optional mutable mapping to use as backing storage. |
None
|
Source code in src/forging_blocks/infrastructure/repositories/in_memory_write_repository.py
delete_by_id(id: TId) -> None
async
¶
Delete an entity by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
TId
|
Unique identifier of the entity. |
required |
Raises:
| Type | Description |
|---|---|
RepositoryError
|
If the ID is None, an empty string, |
RepositoryNotFoundError
|
If no entity exists with the given ID. |
Source code in src/forging_blocks/infrastructure/repositories/in_memory_write_repository.py
save(aggregate: TEntity) -> None
async
¶
Persist an entity instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggregate
|
TEntity
|
The entity to save. |
required |
Raises:
| Type | Description |
|---|---|
RepositoryError
|
If the entity has no valid identifier |