Struct disintegrate_postgres::PgEventStore
source · pub struct PgEventStore<E, S>where
S: Serde<E> + Send + Sync,{ /* private fields */ }
Expand description
PostgreSQL event store implementation.
Implementations§
Trait Implementations§
source§impl<E: Clone, S> Clone for PgEventStore<E, S>where
S: Serde<E> + Send + Sync + Clone,
impl<E: Clone, S> Clone for PgEventStore<E, S>where S: Serde<E> + Send + Sync + Clone,
source§fn clone(&self) -> PgEventStore<E, S>
fn clone(&self) -> PgEventStore<E, S>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<E, S> EventStore<E> for PgEventStore<E, S>where
E: Event + Send + Sync,
S: Serde<E> + Send + Sync,
impl<E, S> EventStore<E> for PgEventStore<E, S>where E: Event + Send + Sync, S: Serde<E> + Send + Sync,
Implementation of the event store using PostgreSQL.
This module provides the implementation of the EventStore
trait for PgEventStore
,
allowing interaction with a PostgreSQL event store. It enables streaming events based on
a query and appending new events to the event store.
source§fn stream<'a, QE>(
&'a self,
query: &'a StreamQuery<QE>
) -> BoxStream<'_, Result<PersistedEvent<QE>, Self::Error>>where
QE: TryFrom<E> + Event + Send + Sync + Clone,
<QE as TryFrom<E>>::Error: StdError + 'static + Send + Sync,
fn stream<'a, QE>( &'a self, query: &'a StreamQuery<QE> ) -> BoxStream<'_, Result<PersistedEvent<QE>, Self::Error>>where QE: TryFrom<E> + Event + Send + Sync + Clone, <QE as TryFrom<E>>::Error: StdError + 'static + Send + Sync,
Streams events based on the provided query.
This function fetches events from the PostgreSQL event store based on the provided
query
. It constructs a SQL query using the SqlEventsCriteriaBuilder
and executes
the query using the sqlx
crate. The fetched events are then converted into
PersistedEvent
instances and streamed as a boxed stream.
Arguments
query
- The stream query specifying the criteria for filtering events.
Returns
A Result
containing a boxed stream of PersistedEvent
that matches the query criteria,
or an error of type Self::Error
.
source§fn append<'life0, 'async_trait, QE>(
&'life0 self,
events: Vec<E>,
query: StreamQuery<QE>,
last_event_id: i64
) -> Pin<Box<dyn Future<Output = Result<Vec<PersistedEvent<E>>, Self::Error>> + Send + 'async_trait>>where
E: Clone + 'async_trait,
QE: Event + Clone + Send + Sync + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
fn append<'life0, 'async_trait, QE>( &'life0 self, events: Vec<E>, query: StreamQuery<QE>, last_event_id: i64 ) -> Pin<Box<dyn Future<Output = Result<Vec<PersistedEvent<E>>, Self::Error>> + Send + 'async_trait>>where E: Clone + 'async_trait, QE: Event + Clone + Send + Sync + 'async_trait, Self: 'async_trait, 'life0: 'async_trait,
Appends new events to the event store.
This function inserts the provided events
into the PostgreSQL event store by performing
two separate inserts. First, it inserts the events into the event_sequence
table to reclaim
a set of IDs for the events. Then, it inserts the events into the event
table along with
their IDs, event types, domain identifiers, and payloads. Finally, it marks the event IDs as consumed
in the event sequence table. If marking the event IDs as consumed fails (e.g., another process has already consumed the IDs),
a conflict error is raised. This conflict indicates that the data retrieved by the query is stale,
meaning that the events generated are no longer valid due to being generated from an old version
of the event store.
Arguments
events
- A vector of events to be appended.query
- The stream query specifying the criteria for filtering events.last_event_id
- The ID of the last consumed event.
Returns
A Result
containing a vector of PersistedEvent
representing the appended events,
or an error of type Self::Error
.