Skip to main content

NeonProjectionStore

Struct NeonProjectionStore 

pub struct NeonProjectionStore<T> { /* private fields */ }
Available on crate feature projection-store only.
Expand description

A projection store over Neon’s serverless /sql HTTP endpoint.

use happenstance_core::ProjectionStore;
use happenstance_neon::{NeonConfig, NeonProjectionStore, NullTransport};

fn takes_a_projection_store<P: ProjectionStore>(_store: &P) {}

let store = NeonProjectionStore::new(NullTransport::new(), NeonConfig::default());
takes_a_projection_store(&store);

Implementations§

§

impl<T> NeonProjectionStore<T>

pub fn new(transport: T, config: NeonConfig) -> Self

Builds a projection store over transport.

Point transport at a read-write primary endpoint, never a read replica. A replica may lag the primary’s commits, so checkpoint could report a position behind a commit this store has already acknowledged. A runner resuming from it applies those events again, and a caller reads a checkpoint it just advanced as behind. ProjectionStore::checkpoint forbids that (PS-38), and nothing in the conformance suite can detect it.

No longer const, and the reason is the stamp above: an identity that distinguishes two store instances cannot be a compile-time constant, because a const fn would give every instance the same one and commit_rejects_a_foreign_batch would pass only for stores that never existed at the same time.

pub const fn transport(&self) -> &T

The transport this store sends round trips through.

pub const fn config(&self) -> &NeonConfig

The table names and limits this store was built with.

Trait Implementations§

§

impl<T: Clone> Clone for NeonProjectionStore<T>

§

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<T: Debug> Debug for NeonProjectionStore<T>

§

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

Formats the value using the given formatter. Read more
§

impl<T: SqlTransport> ProjectionProbe for NeonProjectionStore<T>

The conformance suite’s write and read seam.

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

§

const READS_THROUGH_BATCH: bool = false

false, and it is forced rather than chosen.

A NeonWriteBatch is a list of statements that has been sent to the endpoint exactly never, so there is no open transaction to read through — and answering from committed state is what PS-12 forbids by name. The probe seam being asynchronous since ADR-0062 changes nothing here: the obstacle was never the signature but the transport, which has no interactive transaction for a read to go through.

The two rules that would have used it are emitted as reported skips carrying this reason 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

The adapter’s error if the round trip fails or the answer does not have the shape this adapter asked for.

§

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 the endpoint has never been told about.

§

impl<T: SqlTransport> ProjectionStore for NeonProjectionStore<T>

§

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

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

§Errors

The adapter’s error if the round trip fails, or if the row is one this adapter could not have written.

§

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.

§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, 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 nothing was ever checked out to return.

§Errors

NeonError::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 = NeonError<<T as SqlTransport>::Error>

How this adapter fails.
§

type Batch = NeonWriteBatch

The adapter’s write set. Read more
§

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

Opens a write set. Read more

Auto Trait Implementations§

§

impl<T> Freeze for NeonProjectionStore<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for NeonProjectionStore<T>
where T: RefUnwindSafe,

§

impl<T> Send for NeonProjectionStore<T>
where T: Send,

§

impl<T> Sync for NeonProjectionStore<T>
where T: Sync,

§

impl<T> Unpin for NeonProjectionStore<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for NeonProjectionStore<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for NeonProjectionStore<T>
where T: UnwindSafe,

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