Skip to main content

InMemoryRepository

Struct InMemoryRepository 

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

In-memory repository implementation using HashMap.

This repository is cheap to clone because it uses Arc<RwLock<...>> internally - cloning creates another handle to the same storage. Also includes an embedded InMemoryReadModelStore for read model storage.

Its consumer inbox is dev-only: the dedup set grows unbounded (no TTL, no timestamps) and exists for tests and local development. Use the Postgres or SQLite repository for a production inbox with retention control.

Implementations§

Source§

impl InMemoryRepository

Source

pub fn new() -> Self

Create a new empty repository.

Source

pub fn with_projection_change_retention( self, retention: ProjectionChangeRetention, ) -> Self

Configure the maximum newest projection changes retained per partition.

The persisted compacted-through watermark remains authoritative when this value is lengthened; previously compacted changes are never advertised as restored.

Source

pub fn outbox_store(&self) -> InMemoryOutboxStore

Access the in-memory outbox table handle.

Source

pub fn model_store(&self) -> &InMemoryReadModelStore

Access the embedded read model store directly.

Source

pub fn snapshot_store(&self) -> &InMemorySnapshotStore

Access the embedded snapshot store directly.

Source

pub fn inbox_contains(&self, consumer: &str, message_id: &str) -> bool

Whether a consumer inbox receipt for (consumer, message_id) is recorded.

Source

pub fn clear_inbox(&self) -> usize

Drop every recorded inbox receipt, returning the count removed.

The in-memory equivalent of inbox retention: because this dev-only inbox keeps no timestamps it cannot purge by age, so the only available control is to clear it wholesale (e.g. between test cases).

Trait Implementations§

Source§

impl Clone for InMemoryRepository

Source§

fn clone(&self) -> InMemoryRepository

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 Default for InMemoryRepository

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl GetStream for InMemoryRepository

Source§

fn get_stream<'a>( &'a self, identity: &'a StreamIdentity, ) -> impl Future<Output = Result<Option<Entity>, RepositoryError>> + Send + 'a

Source§

fn get_streams<'a>( &'a self, identities: &'a [StreamIdentity], ) -> impl Future<Output = Result<Vec<Entity>, RepositoryError>> + Send + 'a

Load the streams for the provided identities, skipping missing ones. Read more
Source§

fn get_stream_tail<'a>( &'a self, identity: &'a StreamIdentity, after_version: u64, ) -> impl Future<Output = Result<Option<Entity>, RepositoryError>> + Send + 'a

Load only the events with sequence > after_version as a tail-only Entity (see Entity::load_tail_from_history). Read more
Source§

impl HasOutboxStore for InMemoryRepository

Source§

type OutboxStore = InMemoryOutboxStore

The concrete outbox store this repository produces.
Source§

fn outbox_store(&self) -> Self::OutboxStore

Produce a handle to the durable outbox store.
Source§

impl InboxStore for InMemoryRepository

Source§

fn inbox_contains<'a>( &'a self, consumer: &'a str, message_id: &'a str, ) -> impl Future<Output = Result<bool, RepositoryError>> + Send + 'a

Source§

fn purge_inbox_older_than( &self, _age: Duration, ) -> impl Future<Output = Result<u64, RepositoryError>> + Send

Purge inbox receipts older than age, returning the number removed. Read more
Source§

impl ReadModelWritePlanStore for InMemoryRepository

Source§

impl RelationalReadModelQueryStore for InMemoryRepository

Source§

impl SnapshotStore for InMemoryRepository

Source§

fn get_snapshot<'a>( &'a self, identity: &'a StreamIdentity, ) -> impl Future<Output = Result<Option<SnapshotRecord>, RepositoryError>> + Send + 'a

Source§

fn get_snapshots<'a>( &'a self, identities: &'a [StreamIdentity], ) -> impl Future<Output = Result<Vec<SnapshotRecord>, RepositoryError>> + Send + 'a

Load the snapshots for the provided identities, skipping identities without one. Each returned record carries its own aggregate type/id, so callers can pair records back to identities. Read more
Source§

fn save_snapshot<'a>( &'a self, identity: &'a StreamIdentity, record: SnapshotRecord, ) -> impl Future<Output = Result<(), RepositoryError>> + Send + 'a

Source§

fn delete_snapshot<'a>( &'a self, identity: &'a StreamIdentity, ) -> impl Future<Output = Result<bool, RepositoryError>> + Send + 'a

Source§

impl TransactionalCommit for InMemoryRepository

Source§

fn commit_batch<'a>( &'a self, batch: CommitBatch<'a>, ) -> impl Future<Output = Result<(), RepositoryError>> + Send + 'a

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AggregateBuilder for T

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<R> CommitBuilderExt for R

Source§

fn outbox(&self, msg: OutboxMessage) -> CommitBuilder<'_, Self>

Start an async commit builder chain with an outbox message.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> HasReadModelStore for S

Source§

impl<R> HasRepo for R
where R: Repository,

Source§

type Repo = R

Source§

fn repo(&self) -> &<R as HasRepo>::Repo

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> Queueable for T

Source§

fn queued(self) -> QueuedRepository<Self, InMemoryLockManager>

Wrap with the default async lock manager. Pair with .aggregate::<T>() for per-aggregate serialization over the async repository surface.
Source§

fn queued_with<L: LockManager>( self, lock_manager: L, ) -> QueuedRepository<Self, L>

Wrap with a custom async lock manager.
Source§

impl<S> ReadModelWorkspaceExt for S

Source§

fn workspace(&self) -> ReadModelWorkspace<'_, Self>

Source§

impl<R> ReadModelWritePlanCommitExt for R

Source§

fn read_models( &self, read_models: ReadModelWritePlanBuilder, ) -> CommitBuilder<'_, Self>

Start an async commit builder chain with a relational read-model write plan.
Source§

fn aggregate<'a, A: Aggregate>( &'a self, aggregate: &'a mut A, ) -> StagedCommitBuilder<'a, Self>

Start a staged async commit builder with an aggregate.
Source§

impl<T> Repository for T

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 = Infallible

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.