domain.protocols.repositories¶
src.domain.protocols.repositories
¶
Repository protocols (ports) for domain layer.
This module defines the repository interfaces that the domain layer needs. These are protocols (ports) that will be implemented by the infrastructure layer (adapters).
Following hexagonal architecture: - Domain defines what it needs (protocols/ports) - Infrastructure provides implementations (adapters) - Domain has no knowledge of how data is stored
Classes¶
BaseRepository
¶
Bases: Protocol[T]
Base repository protocol defining common operations.
This is a generic protocol that all repositories should implement. It defines the basic CRUD operations that domain entities need.
The infrastructure layer will provide concrete implementations that work with specific databases (PostgreSQL, MongoDB, etc.)
Source code in src/domain/protocols/repositories.py
Functions¶
save
async
¶
Save an entity to the repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
T
|
The domain entity to save. |
required |
find_by_id
async
¶
Find an entity by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
UUID
|
The UUID of the entity to find. |
required |
Returns:
| Type | Description |
|---|---|
T | None
|
The entity if found, None otherwise. |
delete
async
¶
Delete an entity from the repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
T
|
The entity to delete. |
required |
exists
async
¶
Check if an entity exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_id
|
UUID
|
The UUID of the entity to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the entity exists, False otherwise. |