Skip to main content

AggregateRepository

Struct AggregateRepository 

Source
pub struct AggregateRepository<R, A> { /* private fields */ }
Expand description

Async repository wrapper for a specific aggregate type.

Snapshots are an optional, transparent optimization: with_snapshots(n) configures snapshot caching on this same type, and every method behaves identically with or without it — on commit a snapshot is staged in the same transaction when due, and on load the aggregate is hydrated from a snapshot when one exists.

Implementations§

Source§

impl<R, A> AggregateRepository<R, A>

Source

pub fn new(repo: R) -> Self

Source

pub fn repo(&self) -> &R

Source

pub fn repo_mut(&mut self) -> &mut R

Source§

impl<R, A> AggregateRepository<R, A>
where R: GetStream, A: Aggregate + Send,

Source

pub async fn get(&self, id: &str) -> Result<Option<A>, RepositoryError>

Source

pub async fn get_all(&self, ids: &[&str]) -> Result<Vec<A>, RepositoryError>

Load existing aggregates for the provided ids.

Each id is converted to a StreamIdentity, fetched through get_streams, and hydrated if present. Missing streams are skipped, and backend implementations may return aggregates in storage order rather than input order.

Source§

impl<R, A> AggregateRepository<R, A>

Source

pub async fn commit(&self, aggregate: &mut A) -> Result<(), RepositoryError>

Source

pub async fn commit_all( &self, aggregates: &mut [&mut A], ) -> Result<(), RepositoryError>

Source

pub async fn commit_entities( &self, streams: Vec<(StreamIdentity, &mut Entity)>, ) -> Result<(), RepositoryError>

Source§

impl<R, A> AggregateRepository<R, A>
where R: GetWithOpts, A: Aggregate + Send,

Source

pub async fn get_with( &self, id: &str, opts: ReadOpts, ) -> Result<Option<A>, RepositoryError>

Load an aggregate with options (e.g. ReadOpts::no_lock() to skip the queue lock when the repository is a queued() wrapper).

Source

pub async fn peek(&self, id: &str) -> Result<Option<A>, RepositoryError>

Non-locking read (alias for get_with(ReadOpts::no_lock())).

Source§

impl<R, A> AggregateRepository<R, A>
where R: GetAllWithOpts, A: Aggregate + Send,

Source

pub async fn get_all_with( &self, ids: &[&str], opts: ReadOpts, ) -> Result<Vec<A>, RepositoryError>

Load aggregates for the provided ids with options.

Source

pub async fn peek_all(&self, ids: &[&str]) -> Result<Vec<A>, RepositoryError>

Non-locking multi-read (alias for get_all_with(ReadOpts::no_lock())).

Source§

impl<R, A> AggregateRepository<R, A>

Source

pub async fn abort(&self, aggregate: &A) -> Result<(), RepositoryError>

Release the lock held for an aggregate after an aborted load.

Source

pub async fn unlock(&self, id: &str) -> Result<(), RepositoryError>

Release the lock held for an aggregate id.

Source§

impl<R, A> AggregateRepository<R, A>

Source

pub fn outbox(&self, message: OutboxMessage) -> AggregateCommit<'_, R, A>

Start a commit with an outbox message attached.

Source

pub fn read_models( &self, read_models: ReadModelWritePlanBuilder, ) -> AggregateCommit<'_, R, A>

Start a commit with relational read-model writes attached. Composes with .outbox(..), the aggregate’s events, and snapshots in one transaction.

Source§

impl<R, A> AggregateRepository<R, A>

Source

pub fn with_snapshots(self, frequency: u64) -> Self

Enable snapshot caching at the given event frequency.

Snapshots are a transparent optimization: this configures snapshot behaviour on the same repository type and returns it. On commit a snapshot is staged (when due) in the same transaction; on load the aggregate is hydrated from a snapshot when one exists. Every other method behaves identically with or without snapshots.

Trait Implementations§

Source§

impl<R, A> ConfigurableOutboxPublisher for AggregateRepository<R, A>

Source§

fn configure_outbox_publisher(&mut self, config: OutboxPublisherConfig)

Install the outbox publisher.
Source§

impl<R, A> HasOutboxStore for AggregateRepository<R, A>
where R: HasOutboxStore,

Source§

type OutboxStore = <R as HasOutboxStore>::OutboxStore

The concrete outbox store this repository produces.
Source§

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

Produce a handle to the durable outbox store.
Source§

impl<R, A> HasRepo for AggregateRepository<R, A>

Source§

type Repo = AggregateRepository<R, A>

Source§

fn repo(&self) -> &Self::Repo

Auto Trait Implementations§

§

impl<R, A> !RefUnwindSafe for AggregateRepository<R, A>

§

impl<R, A> !UnwindSafe for AggregateRepository<R, A>

§

impl<R, A> Freeze for AggregateRepository<R, A>
where R: Freeze,

§

impl<R, A> Send for AggregateRepository<R, A>
where R: Send, A: Send,

§

impl<R, A> Sync for AggregateRepository<R, A>
where R: Sync, A: Sync,

§

impl<R, A> Unpin for AggregateRepository<R, A>
where R: Unpin, A: Unpin,

§

impl<R, A> UnsafeUnpin for AggregateRepository<R, A>
where R: UnsafeUnpin,

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

Source§

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

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: AsyncLockManager>( self, lock_manager: L, ) -> QueuedRepository<Self, L>

Wrap with a custom async lock manager.
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.