Trait esrs::store::EventStore
source · pub trait EventStore {
type Aggregate: Aggregate;
type Error: Error;
// Required methods
fn lock<'life0, 'async_trait>(
&'life0 self,
aggregate_id: Uuid
) -> Pin<Box<dyn Future<Output = Result<EventStoreLockGuard, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn by_aggregate_id<'life0, 'async_trait>(
&'life0 self,
aggregate_id: Uuid
) -> Pin<Box<dyn Future<Output = Result<Vec<StoreEvent<<Self::Aggregate as Aggregate>::Event>>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn persist<'life0, 'life1, 'async_trait>(
&'life0 self,
aggregate_state: &'life1 mut AggregateState<<Self::Aggregate as Aggregate>::State>,
events: Vec<<Self::Aggregate as Aggregate>::Event>
) -> Pin<Box<dyn Future<Output = Result<Vec<StoreEvent<<Self::Aggregate as Aggregate>::Event>>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn publish<'life0, 'life1, 'async_trait>(
&'life0 self,
store_events: &'life1 [StoreEvent<<Self::Aggregate as Aggregate>::Event>]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn delete<'life0, 'async_trait>(
&'life0 self,
aggregate_id: Uuid
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
An EventStore is responsible for persisting events that an aggregate emits into a database, and loading the events that represent an aggregate’s history from the database.
Required Associated Types§
Required Methods§
sourcefn lock<'life0, 'async_trait>(
&'life0 self,
aggregate_id: Uuid
) -> Pin<Box<dyn Future<Output = Result<EventStoreLockGuard, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn lock<'life0, 'async_trait>(
&'life0 self,
aggregate_id: Uuid
) -> Pin<Box<dyn Future<Output = Result<EventStoreLockGuard, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Acquires a lock for the given aggregate, or waits for outstanding guards to be released.
Used to prevent concurrent access to the aggregate state.
Note that any process which does not lock
will get immediate (possibly shared!) access.
ALL accesses (regardless of this guard) are subject to the usual optimistic locking strategy on write.
sourcefn by_aggregate_id<'life0, 'async_trait>(
&'life0 self,
aggregate_id: Uuid
) -> Pin<Box<dyn Future<Output = Result<Vec<StoreEvent<<Self::Aggregate as Aggregate>::Event>>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn by_aggregate_id<'life0, 'async_trait>(
&'life0 self,
aggregate_id: Uuid
) -> Pin<Box<dyn Future<Output = Result<Vec<StoreEvent<<Self::Aggregate as Aggregate>::Event>>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Loads the events that an aggregate instance has emitted in the past.
sourcefn persist<'life0, 'life1, 'async_trait>(
&'life0 self,
aggregate_state: &'life1 mut AggregateState<<Self::Aggregate as Aggregate>::State>,
events: Vec<<Self::Aggregate as Aggregate>::Event>
) -> Pin<Box<dyn Future<Output = Result<Vec<StoreEvent<<Self::Aggregate as Aggregate>::Event>>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn persist<'life0, 'life1, 'async_trait>(
&'life0 self,
aggregate_state: &'life1 mut AggregateState<<Self::Aggregate as Aggregate>::State>,
events: Vec<<Self::Aggregate as Aggregate>::Event>
) -> Pin<Box<dyn Future<Output = Result<Vec<StoreEvent<<Self::Aggregate as Aggregate>::Event>>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Persists multiple events into the database. This should be done in a single transaction - either all the events are persisted correctly, or none are.
Persisting events may additionally trigger configured event handlers (transactional and non-transactional).
sourcefn publish<'life0, 'life1, 'async_trait>(
&'life0 self,
store_events: &'life1 [StoreEvent<<Self::Aggregate as Aggregate>::Event>]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn publish<'life0, 'life1, 'async_trait>(
&'life0 self,
store_events: &'life1 [StoreEvent<<Self::Aggregate as Aggregate>::Event>]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Publish multiple events on the configured events buses.
sourcefn delete<'life0, 'async_trait>(
&'life0 self,
aggregate_id: Uuid
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn delete<'life0, 'async_trait>(
&'life0 self,
aggregate_id: Uuid
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Delete all events from events store related to given aggregate_id
.
Moreover it should delete all the read side projections triggered by event handlers.
Implementors§
source§impl<A, E, T, S> EventStore for T
impl<A, E, T, S> EventStore for T
Blanket implementation making an EventStore
every (smart) pointer to an EventStore
,
e.g. &Store
, Box<Store>
, Arc<Store>
.
This is particularly useful when there’s the need in your codebase to have a generic EventStore
.