spakky-data¶
Repository, Transaction 추상화 — 데이터 접근 계층
spakky-data는 core 레이어의 추상 계약만 제공합니다. 애플리케이션에서 SQLAlchemy로
영속화를 구현하려면 spakky-sqlalchemy를 함께 설치하고, AbstractMappableTable /
AbstractAsyncGenericRepository 또는 AbstractGenericRepository를 사용하세요.
사용자 흐름은 데이터베이스 가이드를 먼저 보는 편이 좋습니다. 이 페이지는 실제 API 표면을 확인하기 위한 레퍼런스입니다.
스테레오타입¶
spakky.data.stereotype.repository
¶
Repository stereotype for data access layer.
This module provides @Repository stereotype for organizing classes that handle data persistence and retrieval.
Repository(*, name='', scope=Scope.SINGLETON)
dataclass
¶
Bases: Pod
Stereotype for repository classes handling data access.
Repositories provide an abstraction over data sources, implementing data access patterns and queries.
options: show_root_heading: false
영속성¶
spakky.data.persistency.repository
¶
EntityNotFoundError
¶
VersionConflictError
¶
Bases: AbstractSpakkyDomainError
Raised when optimistic locking detects a version conflict during save.
IGenericRepository
¶
Bases: ABC
Synchronous generic repository interface for aggregate persistence.
get(aggregate_id)
abstractmethod
¶
get_or_none(aggregate_id)
abstractmethod
¶
contains(aggregate_id)
abstractmethod
¶
range(aggregate_ids)
abstractmethod
¶
save(aggregate)
abstractmethod
¶
save_all(aggregates)
abstractmethod
¶
Persist multiple aggregates and return the saved instances.
delete(aggregate)
abstractmethod
¶
delete_all(aggregates)
abstractmethod
¶
Delete multiple aggregates and return the deleted instances.
IAsyncGenericRepository
¶
Bases: ABC
Asynchronous generic repository interface for aggregate persistence.
get(aggregate_id)
abstractmethod
async
¶
get_or_none(aggregate_id)
abstractmethod
async
¶
contains(aggregate_id)
abstractmethod
async
¶
range(aggregate_ids)
abstractmethod
async
¶
save(aggregate)
abstractmethod
async
¶
save_all(aggregates)
abstractmethod
async
¶
Persist multiple aggregates and return the saved instances.
delete(aggregate)
abstractmethod
async
¶
delete_all(aggregates)
abstractmethod
async
¶
Delete multiple aggregates and return the deleted instances.
options: show_root_heading: false
spakky.data.persistency.transaction
¶
AbstractTransaction(autocommit=True)
¶
Bases: IDisposable, ABC
Abstract base for synchronous transaction context managers.
Initialize the transaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
autocommit
|
bool
|
Whether to auto-commit on successful exit. |
True
|
Source code in core/spakky-data/src/spakky/data/persistency/transaction.py
AbstractAsyncTransaction(autocommit=True)
¶
Bases: IAsyncDisposable, ABC
Abstract base for asynchronous transaction context managers.
Initialize the async transaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
autocommit
|
bool
|
Whether to auto-commit on successful exit. |
True
|
Source code in core/spakky-data/src/spakky/data/persistency/transaction.py
options: show_root_heading: false
spakky.data.persistency.aggregate_collector
¶
AggregateCollector()
¶
Context-scoped collector for tracking aggregates saved in a transaction.
Source code in core/spakky-data/src/spakky/data/persistency/aggregate_collector.py
collect(aggregate)
¶
Track an aggregate that was saved during the transaction.
This method is called by Repository implementations after saving an aggregate to the database. The collector stores a reference to track which aggregates were modified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggregate
|
AbstractAggregateRoot
|
The aggregate to track. |
required |
Example
collector = AggregateCollector() user = User.create(name="Alice") collector.collect(user)
Source code in core/spakky-data/src/spakky/data/persistency/aggregate_collector.py
all()
¶
Get all tracked aggregates.
Returns a sequence of all aggregates collected during the current transaction. This is typically called by aspects after the use case logic completes to extract domain events.
Returns:
| Type | Description |
|---|---|
Sequence[AbstractAggregateRoot]
|
Sequence of tracked aggregates. |
Example
collector = AggregateCollector() user = User.create(name="Bob") collector.collect(user) aggregates = collector.get_all() len(aggregates) 1
Source code in core/spakky-data/src/spakky/data/persistency/aggregate_collector.py
clear()
¶
Clear all tracked aggregates.
This method is called after events have been published or when a transaction completes (success or failure) to prepare the collector for the next transaction.
Example
collector = AggregateCollector() user = User.create(name="Charlie") collector.collect(user) collector.clear() len(collector.get_all()) 0
Source code in core/spakky-data/src/spakky/data/persistency/aggregate_collector.py
options: show_root_heading: false
spakky.data.persistency.error
¶
AbstractSpakkyPersistencyError
¶
Bases: AbstractSpakkyFrameworkError, ABC
Base error for persistency layer operations.
options: show_root_heading: false
외부 Proxy¶
spakky.data.external.proxy
¶
IGenericProxy
¶
options: show_root_heading: false
spakky.data.external.error
¶
AbstractSpakkyExternalError
¶
Bases: AbstractSpakkyFrameworkError, ABC
Base error for external proxy operations.
options: show_root_heading: false
Aspect¶
spakky.data.aspects.transactional
¶
Transactional()
dataclass
¶
Bases: FunctionAnnotation
Annotation for marking methods as transactional.
Methods decorated with @Transactional() will be executed within a transaction context, ensuring atomicity of operations.
AsyncTransactionalAspect(transaction)
¶
Bases: IAsyncAspect
Aspect for managing transactions in async methods.
Intercepts async methods decorated with @Transactional and ensures that they are executed within a transaction context.
Source code in core/spakky-data/src/spakky/data/aspects/transactional.py
TransactionalAspect(transaction)
¶
Bases: IAspect
Aspect for managing transactions in sync methods.
Intercepts sync methods decorated with @Transactional and ensures that they are executed within a transaction context.
Source code in core/spakky-data/src/spakky/data/aspects/transactional.py
transactional(func)
¶
Decorator for marking methods as transactional.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[P, R]
|
The function to decorate. |
required |
Returns: The decorated function with transactional annotation.
Source code in core/spakky-data/src/spakky/data/aspects/transactional.py
options: show_root_heading: false