EventStore

Trait EventStore 

Source
pub trait EventStore {
    type SourceId: Eq;
    type Event;
    type Error: AppendError;

    // Required methods
    fn append(
        &mut self,
        source_id: Self::SourceId,
        version: Expected,
        events: Vec<Self::Event>,
    ) -> BoxFuture<'_, Result<u32, Self::Error>>;
    fn stream(
        &self,
        source_id: Self::SourceId,
        select: Select,
    ) -> BoxFuture<'_, Result<EventStream<'_, Self>, Self::Error>>;
    fn stream_all(
        &self,
        select: Select,
    ) -> BoxFuture<'_, Result<EventStream<'_, Self>, Self::Error>>;
    fn remove(
        &mut self,
        source_id: Self::SourceId,
    ) -> BoxFuture<'_, Result<(), Self::Error>>;
}
Expand description

An Event Store is an append-only, ordered list of Events for a certain “source” – e.g. an Aggregate.

Required Associated Types§

Source

type SourceId: Eq

Type of the Source id, typically an AggregateId.

Source

type Event

Event to be stored in the EventStore, typically an Aggregate::Event.

Source

type Error: AppendError

Possible errors returned by the EventStore when requesting operations.

Required Methods§

Source

fn append( &mut self, source_id: Self::SourceId, version: Expected, events: Vec<Self::Event>, ) -> BoxFuture<'_, Result<u32, Self::Error>>

Appends a new list of Events to the Event Store, for the Source entity specified by SourceId.

append is a transactional operation: it either appends all the events, or none at all and returns an AppendError.

The desired version for the new Events to append must be specified through an Expected element.

When using Expected::Any, no checks on the current [Aggregate] values will be performed, disregarding optimistic locking.

When using Expected::Exact, the Store will check that the current version of the [Aggregate] is exactly the one specified.

If the version is not the one expected from the Store, implementations should raise an AppendError::Conflict error.

Implementations could decide to return an error if the expected version is different from the one supplied in the method invocation.

Source

fn stream( &self, source_id: Self::SourceId, select: Select, ) -> BoxFuture<'_, Result<EventStream<'_, Self>, Self::Error>>

Streams a list of Events from the EventStore back to the application, by specifying the desired SourceId and Select operation.

SourceId will be used to request a particular EventStream.

Select specifies the selection strategy for the Events in the returned EventStream: take a look at type documentation for all the available options.

Source

fn stream_all( &self, select: Select, ) -> BoxFuture<'_, Result<EventStream<'_, Self>, Self::Error>>

Streams a list of Events from the EventStore back to the application, disregarding the SourceId values but using a Select operation.

SourceId will be used to request a particular EventStream.

Select specifies the selection strategy for the Events in the returned EventStream: take a look at type documentation for all the available options.

Source

fn remove( &mut self, source_id: Self::SourceId, ) -> BoxFuture<'_, Result<(), Self::Error>>

Drops all the Events related to one Source, specified by the provided SourceId.

Implementors§