Struct NeonProjectionStore
pub struct NeonProjectionStore<T> { /* private fields */ }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>
impl<T> NeonProjectionStore<T>
pub fn new(transport: T, config: NeonConfig) -> Self
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 config(&self) -> &NeonConfig
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>
impl<T: Clone> Clone for NeonProjectionStore<T>
§impl<T: Debug> Debug for NeonProjectionStore<T>
impl<T: Debug> Debug for NeonProjectionStore<T>
§impl<T: SqlTransport> ProjectionProbe for NeonProjectionStore<T>
The conformance suite’s write and read seam.
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
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>
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>
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>
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>
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>
impl<T: SqlTransport> ProjectionStore for NeonProjectionStore<T>
§async fn checkpoint(&self, id: &ProjectionId) -> Result<Checkpoint, Self::Error>
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>>
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
CommitError::ForeignBatchifbatchwas begun on a different store instance — or byNeonWriteBatch::new, which begins nothing — decided before anything is serialised;CommitError::CheckpointRegressionifpositionis below the one recorded; equal is accepted, because a batch that wrote nothing new still records that its events were considered;CommitError::Storeif the transport or the endpoint failed.
§async fn reset(
&self,
batch: Self::Batch,
id: &ProjectionId,
) -> Result<(), ResetError<Self::Error>>
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::ForeignBatchifbatchwas begun on a different store instance;ResetError::Storeif the transport or the endpoint failed.
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>
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.