pub struct PgEventStore<E, S>{ /* private fields */ }Expand description
PostgreSQL event store implementation.
Implementations§
Source§impl<E, S> PgEventStore<E, S>
impl<E, S> PgEventStore<E, S>
Sourcepub async fn try_new(pool: PgPool, serde: S) -> Result<Self, Error>
pub async fn try_new(pool: PgPool, serde: S) -> Result<Self, Error>
Initializes the PostgreSQL DB and returns a new instance of PgEventStore.
§Arguments
pool- The PostgreSQL connection pool.serde- The serialization implementation for the event payload.
Sourcepub fn new_uninitialized(pool: PgPool, serde: S) -> Self
pub fn new_uninitialized(pool: PgPool, serde: S) -> Self
Creates a new instance of PgEventStore.
This constructor does not initialize the database or add the
domain_id columns necessary for disintegrate to function properly.
If you need to initialize the database, use PgEventStore::new instead.
If you plan to use this constructor, ensure that the disintegrate is
properly initialized. Refer to the SQL files in the “event_store/sql” directory
to recreate the default structure. Additionally, all domain_id columns
and their corresponding indexes must be created manually.
§Arguments
pool- The PostgreSQL connection pool.serde- The serialization implementation for the event payload.
Trait Implementations§
Source§impl<E: Clone, S> Clone for PgEventStore<E, S>
impl<E: Clone, S> Clone for PgEventStore<E, S>
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<i64, E> for PgEventStore<E, S>
Implementation of the event store using PostgreSQL.
impl<E, S> EventStore<i64, E> for PgEventStore<E, S>
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<PgEventId, QE>,
) -> BoxStream<'a, Result<StreamItem<PgEventId, QE>, Self::Error>>
fn stream<'a, QE>( &'a self, query: &'a StreamQuery<PgEventId, QE>, ) -> BoxStream<'a, Result<StreamItem<PgEventId, QE>, Self::Error>>
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<PgEventId, QE>,
version: PgEventId,
) -> Pin<Box<dyn Future<Output = Result<Vec<PersistedEvent<PgEventId, E>>, Self::Error>> + Send + 'async_trait>>
fn append<'life0, 'async_trait, QE>( &'life0 self, events: Vec<E>, query: StreamQuery<PgEventId, QE>, version: PgEventId, ) -> Pin<Box<dyn Future<Output = Result<Vec<PersistedEvent<PgEventId, E>>, Self::Error>> + Send + 'async_trait>>
Appends new events to the event store.
This function inserts the provided events into the PostgreSQL-backed event store.
Before inserting, it queries the event table to ensure that no events have been
appended since the given version. If newer events are found, a concurrency error
is returned to prevent invalid state transitions.
If the concurrency check succeeds, the events are inserted into the event table.
§Arguments
events- The events to append to the event store.query- The stream query that identifies the target event stream.version- The ID of the last consumed event, used for optimistic concurrency control.
§Returns
A Result containing a vector of PersistedEvent representing the appended events,
or an error of type Self::Error.
Source§fn append_without_validation<'life0, 'async_trait>(
&'life0 self,
events: Vec<E>,
) -> Pin<Box<dyn Future<Output = Result<Vec<PersistedEvent<PgEventId, E>>, Self::Error>> + Send + 'async_trait>>where
E: Clone + '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<PgEventId, E>>, Self::Error>> + Send + 'async_trait>>where
E: Clone + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
Appends a batch of events to the PostgreSQL-backed event store without verifying whether new events have been added since the last read.
§Arguments
events- A vector of events to be appended.
§Returns
A Result containing a vector of PersistedEvent representing the appended events,
or an error of type Self::Error.
type Error = Error
Auto Trait Implementations§
impl<E, S> Freeze for PgEventStore<E, S>where
S: Freeze,
impl<E, S> !RefUnwindSafe for PgEventStore<E, S>
impl<E, S> Send for PgEventStore<E, S>where
E: Send,
impl<E, S> Sync for PgEventStore<E, S>where
E: Sync,
impl<E, S> Unpin for PgEventStore<E, S>
impl<E, S> !UnwindSafe for PgEventStore<E, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more