EventStore

Trait EventStore 

Source
pub trait EventStore<ID, E>
where ID: EventId, E: Event + Send + Sync,
{ type Error: Send + Sync; // Required methods fn stream<'a, QE>( &'a self, query: &'a StreamQuery<ID, QE>, ) -> BoxStream<'a, Result<StreamItem<ID, QE>, Self::Error>> where QE: TryFrom<E> + Event + 'static + Clone + Send + Sync, <QE as TryFrom<E>>::Error: StdError + 'static + Send + Sync; fn append<'life0, 'async_trait, QE>( &'life0 self, events: Vec<E>, query: StreamQuery<ID, QE>, last_event_id: ID, ) -> Pin<Box<dyn Future<Output = Result<Vec<PersistedEvent<ID, E>>, Self::Error>> + Send + 'async_trait>> where E: Clone + 'async_trait, QE: Event + 'static + Clone + Send + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait; fn append_without_validation<'life0, 'async_trait>( &'life0 self, events: Vec<E>, ) -> Pin<Box<dyn Future<Output = Result<Vec<PersistedEvent<ID, E>>, Self::Error>> + Send + 'async_trait>> where E: Clone + 'async_trait, Self: 'async_trait, 'life0: 'async_trait; }
Expand description

An event store.

This trait provides methods for streaming events and appending events to the event store.

Required Associated Types§

Required Methods§

Source

fn stream<'a, QE>( &'a self, query: &'a StreamQuery<ID, QE>, ) -> BoxStream<'a, Result<StreamItem<ID, QE>, Self::Error>>
where QE: TryFrom<E> + Event + 'static + Clone + Send + Sync, <QE as TryFrom<E>>::Error: StdError + 'static + Send + Sync,

§Arguments
  • query - The stream query specifying the filtering conditions.
§Returns

A Result containing a boxed stream of StreamItem matching the query, or an error.

Source

fn append<'life0, 'async_trait, QE>( &'life0 self, events: Vec<E>, query: StreamQuery<ID, QE>, last_event_id: ID, ) -> Pin<Box<dyn Future<Output = Result<Vec<PersistedEvent<ID, E>>, Self::Error>> + Send + 'async_trait>>
where E: Clone + 'async_trait, QE: Event + 'static + Clone + Send + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Appends a batch of events to the event store.

§Arguments
  • events - A vector of events to append to the event store.
  • query - The stream query associated with the appended events.
  • last_event_id - The ID of the last event in the event stream that was queried before appending.
§Returns

A Result containing a vector of PersistedEvent representing the appended events, or an error.

§Notes

The append method re-executes the query and checks if there are new events between the last_event_id queried and the appended events’ IDs. If new events are found, a conflict has occurred, and the conflict handling mechanism should be implemented accordingly.

Source

fn append_without_validation<'life0, 'async_trait>( &'life0 self, events: Vec<E>, ) -> Pin<Box<dyn Future<Output = Result<Vec<PersistedEvent<ID, E>>, Self::Error>> + Send + 'async_trait>>
where E: Clone + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,

Appends a batch of events to the event store without verifying if new events have been added since the last read.

This method is useful when you are certain that no other process has modified the event store in a way that would make your logic stale.

If you need to guarantee that no duplicate events are added, use the append method instead, providing a query that ensures uniqueness.

§Arguments
  • events - A vector of events to append to the event store.
§Returns

A Result containing a vector of PersistedEvent representing the appended events, or an error.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§