Skip to main content

PostgresProjectionStore

Struct PostgresProjectionStore 

#[non_exhaustive]
pub struct PostgresProjectionStore { /* private fields */ }
Available on crate feature projection-store only.
Expand description

A Postgres-backed projection store.

Implementations§

§

impl PostgresProjectionStore

pub fn new(pool: PgPool) -> Self

Wraps an existing pool.

Sharing one pool with PostgresEventStore is the expected deployment, which is why neither type builds its own.

pub fn pool(&self) -> &PgPool

The pool this store writes through.

Trait Implementations§

§

impl Clone for PostgresProjectionStore

§

fn clone(&self) -> Self

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
§

impl Debug for PostgresProjectionStore

§

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

Formats the value using the given formatter. Read more
§

impl ProjectionProbe for PostgresProjectionStore

The conformance suite’s write and read seam.

It lives here, in src/, and not in tests/projection.rs: that is a different crate, where neither ProjectionProbe nor PostgresProjectionStore is local and the orphan rule answers error[E0117].

§

const READS_THROUGH_BATCH: bool = false

false, and it is the honest answer rather than a gap.

A PostgresProjectionBatch is a list of statements that has been sent to Postgres exactly never, so there is no open transaction to read through — and answering from committed state is what PS-12 forbids by name. The two rules that would have used it are emitted as reported skips rather than omitted.

§

async fn probe_write( &self, batch: &mut Self::Batch, key: &str, value: u64, ) -> Result<(), Self::Error>

Queues one probe row. Never awaits and never fails, because queueing a statement into a buffer the caller owns cannot fail.

§

async fn probe_delete_all( &self, batch: &mut Self::Batch, ) -> Result<(), Self::Error>

Queues removal of every probe row, so that reset can be checked without the suite knowing what a read model is.

§

async fn probe_read(&self, key: &str) -> Result<Option<u64>, Self::Error>

Reads one probe row from committed state.

§Errors

PostgresProjectionStoreError::Driver if the pool or the server rejected the read.

§

async fn probe_read_through( &self, _batch: &mut Self::Batch, _key: &str, ) -> Result<Option<u64>, Self::Error>

Never called, because READS_THROUGH_BATCH is false.

§Panics

Always. The specification permits exactly this for an adapter whose batch has no read path, and the panic is the honest answer: any value returned here would be a claim about pending writes Postgres has never been told about.

§

impl SendProjectionStore for PostgresProjectionStore

§

type Batch = PostgresProjectionBatch

An owned buffered write set. See the module documentation for why this is not sqlx::Transaction<'static, Postgres>, which is what this line said while every body below was todo!().

§

async fn begin(&self) -> Result<Self::Batch, Self::Error>

Never awaits and never fails: minting an empty Vec and copying a u64 touches no connection. The signature is async and fallible for the live store’s sake, and this body is what PS-6’s discipline looks like on a buffer.

§

async fn checkpoint(&self, id: &ProjectionId) -> Result<Checkpoint, Self::Error>

Reads id’s checkpoint, or Checkpoint::NeverRun when it has no row.

The absence of a row is the NeverRun state, which is why a successful reset deletes rather than writing a sentinel: a sentinel position would make a reset indistinguishable from a commit at the first position.

§Errors
§

async fn commit( &self, batch: Self::Batch, id: &ProjectionId, position: SequencePosition, authority: Authority, ) -> Result<(), CommitError<Self::Error>>

Applies batch and advances id’s checkpoint to position, as one unit.

§How the regression guard is built, and why not the obvious way

The upsert carries its own guard — ON CONFLICT … DO UPDATE … WHERE projection_checkpoint.position <= excluded.position — so two runners racing on one ProjectionId are serialised by the row lock ON CONFLICT DO UPDATE takes, without this adapter holding a lock of its own. happenstance-sqlite reads the recorded position first and relies on a global write lock; Postgres has no such lock, which is the point of this crate.

A guarded upsert reports a regression as zero rows and cannot say what the recorded position was: RETURNING on a DO UPDATE yields the new row, and Postgres exposes no OLD there. So the recorded value is re-read inside the same transaction before the error is built — CommitError::CheckpointRegression carries both values so a caller can log the gap rather than spend a second round trip on it.

The transaction is rolled back on that path, and that is not bookkeeping: the caller’s statements are already in it, and a refused commit that left the read model written would be a partial application with no checkpoint to record it.

§Errors
§

async fn reset( &self, batch: Self::Batch, id: &ProjectionId, ) -> Result<(), ResetError<Self::Error>>

Applies batch and returns id to Checkpoint::NeverRun, as one unit.

commit’s dual. It deletes nothing this adapter chose: the read model is the caller’s, and an adapter that truncated a table of its own naming would be scoped to something the port deliberately never told it.

§Errors

ResetError::Refused is never returned: this store holds no protection policy, which is PS-18’s mechanism left unexercised by a store with nothing to protect.

§

async fn rollback(&self, batch: Self::Batch) -> Result<(), Self::Error>

Discards the batch without committing.

Nothing was ever sent to Postgres, so this is a drop — which is also the evidence PS-7 asks for: for a buffering adapter, “dropping a batch must roll back” is free, and the store is usable afterwards because no connection was ever checked out to return.

§Errors

PostgresProjectionStoreError::ForeignBatch if batch was begun on a different store instance. The batch is consumed either way; the refusal is how a caller learns it was holding the wrong one, on the call that was meant to be the cleanup.

§

type Error = PostgresProjectionStoreError

How this adapter fails.

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
§

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

§

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.

§

impl<T> Instrument for T

§

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

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

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<TraitVariantBlanketType> ProjectionStore for TraitVariantBlanketType
where TraitVariantBlanketType: SendProjectionStore,

Source§

type Error = <TraitVariantBlanketType as SendProjectionStore>::Error

How this adapter fails.
Source§

type Batch = <TraitVariantBlanketType as SendProjectionStore>::Batch

The adapter’s write set. Read more
Source§

async fn begin( &self, ) -> Result<<TraitVariantBlanketType as ProjectionStore>::Batch, <TraitVariantBlanketType as ProjectionStore>::Error>

Opens a write set. Read more
Source§

async fn checkpoint( &self, id: &ProjectionId, ) -> Result<Checkpoint, <TraitVariantBlanketType as ProjectionStore>::Error>

How far this projection has been brought, and whether its rows are authoritative. Read more
Source§

async fn commit( &self, batch: <TraitVariantBlanketType as ProjectionStore>::Batch, id: &ProjectionId, position: SequencePosition, authority: Authority, ) -> Result<(), CommitError<<TraitVariantBlanketType as ProjectionStore>::Error>>

Applies batch and moves id’s checkpoint to position, as one unit. Read more
Source§

async fn reset( &self, batch: <TraitVariantBlanketType as ProjectionStore>::Batch, id: &ProjectionId, ) -> Result<(), ResetError<<TraitVariantBlanketType as ProjectionStore>::Error>>

Applies batch and returns id to Checkpoint::NeverRun, as one unit. Read more
Source§

async fn rollback( &self, batch: <TraitVariantBlanketType as ProjectionStore>::Batch, ) -> Result<(), <TraitVariantBlanketType as ProjectionStore>::Error>

Discards the batch without committing. Read more
§

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, !>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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