Skip to main content

PostgresStore

Struct PostgresStore 

Source
pub struct PostgresStore { /* private fields */ }
Expand description

A persistence store backed by PostgreSQL, implementing both EventStore and SnapshotStore over a shared connection pool; cheap to clone.

Implementations§

Source§

impl PostgresStore

Source

pub fn new(pool: PgPool) -> Self

Create a store over the given connection pool. The schema is not touched; apply it via PostgresStore::migrate or manage it externally.

Source

pub async fn migrate(&self) -> Result<(), Error>

Apply the embedded schema migrations, idempotently.

Trait Implementations§

Source§

impl Clone for PostgresStore

Source§

fn clone(&self) -> PostgresStore

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PostgresStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl EventStore for PostgresStore

Source§

type Error = Error

The type of the store’s failures. Send, Sync and 'static are required by the Send variant of this trait anyway; stating them here reports a non-conforming error type at its definition instead of at an opaque future, and lets callers box or propagate store failures across tasks.
Source§

async fn append( &self, id: &PersistenceId, next_seq_no: SeqNo, events: Vec<EncodedEvent>, ) -> Result<(), AppendError<Self::Error>>

Append the given events at sequence number next_seq_no, the first one taking that number, atomically: after a crash the stream contains all of them or none. The append is conditional: if the stream’s actual next sequence number differs from next_seq_no, another writer has extended the stream and the append must fail with AppendError::Conflict, leaving the stream untouched; this fences concurrent incarnations. next_seq_no is SeqNo::ZERO for an empty stream. An empty events appends nothing but is still conditional.
Source§

async fn read( &self, id: &PersistenceId, from_seq_no: SeqNo, limit: NonZeroUsize, ) -> Result<Vec<StoredEvent>, Self::Error>

Read up to limit events from the given sequence number on, inclusive, in ascending order. Replay pages through this until a page is short.
Source§

impl SnapshotStore for PostgresStore

Source§

type Error = Error

The type of the store’s failures. Send, Sync and 'static are required by the Send variant of this trait anyway; stating them here reports a non-conforming error type at its definition instead of at an opaque future, and lets callers box or propagate store failures across tasks.
Source§

async fn save( &self, id: &PersistenceId, next_seq_no: SeqNo, snapshot: EncodedSnapshot, ) -> Result<(), Self::Error>

Save the given snapshot together with next_seq_no, the sequence number at which replay resumes, replacing any earlier snapshot: only the latest one is ever loaded.
Source§

async fn load( &self, id: &PersistenceId, ) -> Result<Option<StoredSnapshot>, Self::Error>

Load the latest snapshot, if any.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more