Repository

Struct Repository 

Source
pub struct Repository<S, C = Optimistic, M = NoSnapshots<<S as EventStore>::Id, <S as EventStore>::Position>>{ /* private fields */ }
Expand description

Repository.

Implementations§

Source§

impl<S> Repository<S>
where S: EventStore,

Source

pub const fn new(store: S) -> Self

Source§

impl<S, M> Repository<S, Optimistic, M>
where S: EventStore,

Source

pub fn without_concurrency_checking(self) -> Repository<S, Unchecked, M>

Disable optimistic concurrency checking for this repository.

Source§

impl<S, C, M> Repository<S, C, M>

Source

pub const fn event_store(&self) -> &S

Source

pub fn build_projection<P>(&self) -> ProjectionBuilder<'_, S, P>
where P: Projection<Id = S::Id>,

Source

pub fn with_snapshots<SS>( self, snapshots: SS, ) -> Repository<S, C, Snapshots<SS>>
where SS: SnapshotStore<Id = S::Id, Position = S::Position>,

Source§

impl<S, C> Repository<S, C, NoSnapshots<S::Id, S::Position>>

Source

pub const fn aggregate_builder<A>(&self) -> AggregateBuilder<'_, Self, A>
where A: Aggregate<Id = S::Id>,

Source

pub async fn load<A>( &self, id: &S::Id, ) -> Result<A, ProjectionError<<S as EventStore>::Error, <<S as EventStore>::Codec as Codec>::Error>>
where A: Aggregate<Id = S::Id>, A::Event: ProjectionEvent,

Load an aggregate by replaying all events (no snapshots).

§Errors

Returns ProjectionError if the store fails to load events or if an event cannot be decoded into the aggregate’s event sum type.

Source§

impl<S> Repository<S, Unchecked>
where S: EventStore,

Source

pub async fn execute_command<A, Cmd>( &mut self, id: &S::Id, command: &Cmd, metadata: &S::Metadata, ) -> UncheckedCommandResult<A, S>
where A: Aggregate<Id = S::Id> + Handle<Cmd>, A::Event: ProjectionEvent + SerializableEvent, Cmd: Sync, S::Metadata: Clone,

Execute a command with last-writer-wins semantics (no concurrency checking).

§Errors

Returns CommandError when the aggregate rejects the command, events cannot be encoded, the store fails to persist, or the aggregate cannot be rebuilt.

Source§

impl<S> Repository<S, Optimistic>
where S: EventStore,

Source

pub async fn execute_command<A, Cmd>( &mut self, id: &S::Id, command: &Cmd, metadata: &S::Metadata, ) -> OptimisticCommandResult<A, S>
where A: Aggregate<Id = S::Id> + Handle<Cmd>, A::Event: ProjectionEvent + SerializableEvent, Cmd: Sync, S::Metadata: Clone,

Execute a command using optimistic concurrency control.

§Errors

Returns OptimisticCommandError::Concurrency if the stream version changed between loading and committing. Other variants cover aggregate validation, encoding, persistence, and projection rebuild errors.

Source

pub async fn execute_with_retry<A, Cmd>( &mut self, id: &S::Id, command: &Cmd, metadata: &S::Metadata, max_retries: usize, ) -> RetryResult<A, S>
where A: Aggregate<Id = S::Id> + Handle<Cmd>, A::Event: ProjectionEvent + SerializableEvent, Cmd: Sync, S::Metadata: Clone,

Execute a command with automatic retry on concurrency conflicts.

§Errors

Returns the last error if all retries are exhausted, or a non-concurrency error immediately.

Source§

impl<S, SS, C> Repository<S, C, Snapshots<SS>>
where S: EventStore, SS: SnapshotStore<Id = S::Id, Position = S::Position>, C: ConcurrencyStrategy,

Source

pub const fn snapshot_store(&self) -> &SS

Source

pub const fn aggregate_builder<A>(&self) -> AggregateBuilder<'_, Self, A>
where A: Aggregate<Id = S::Id> + Serialize + DeserializeOwned,

Source

pub async fn load<A>( &self, id: &S::Id, ) -> Result<A, ProjectionError<<S as EventStore>::Error, <<S as EventStore>::Codec as Codec>::Error>>

Load an aggregate using snapshots when available.

§Errors

Returns ProjectionError if the store fails to load events, if an event cannot be decoded, or if a stored snapshot cannot be deserialized (which indicates snapshot corruption).

Source§

impl<S, SS> Repository<S, Unchecked, Snapshots<SS>>
where S: EventStore, SS: SnapshotStore<Id = S::Id, Position = S::Position>,

Source

pub async fn execute_command<A, Cmd>( &mut self, id: &S::Id, command: &Cmd, metadata: &S::Metadata, ) -> UncheckedSnapshotCommandResult<A, S, SS>

Execute a command with last-writer-wins semantics and optional snapshotting.

§Errors

Returns SnapshotCommandError when the aggregate rejects the command, events cannot be encoded, the store fails to persist, snapshot persistence fails, or the aggregate cannot be rebuilt.

§Panics

Panics if the store reports None from stream_version after a successful append. This indicates a bug in the event store implementation.

Source§

impl<S, SS> Repository<S, Optimistic, Snapshots<SS>>
where S: EventStore, SS: SnapshotStore<Id = S::Id, Position = S::Position>,

Source

pub async fn execute_command<A, Cmd>( &mut self, id: &S::Id, command: &Cmd, metadata: &S::Metadata, ) -> OptimisticSnapshotCommandResult<A, S, SS>

Execute a command using optimistic concurrency control and optional snapshotting.

§Errors

Returns OptimisticSnapshotCommandError::Concurrency if the stream version changed between loading and committing. Other variants cover aggregate validation, encoding, persistence, snapshot persistence, and projection rebuild errors.

§Panics

Panics if the store reports None from stream_version after a successful append. This indicates a bug in the event store implementation.

Source

pub async fn execute_with_retry<A, Cmd>( &mut self, id: &S::Id, command: &Cmd, metadata: &S::Metadata, max_retries: usize, ) -> SnapshotRetryResult<A, S, SS>

Execute a command with automatic retry on concurrency conflicts.

§Errors

Returns the last error if all retries are exhausted, or a non-concurrency error immediately.

Auto Trait Implementations§

§

impl<S, C, M> Freeze for Repository<S, C, M>
where S: Freeze, M: Freeze,

§

impl<S, C, M> RefUnwindSafe for Repository<S, C, M>

§

impl<S, C, M> Send for Repository<S, C, M>
where M: Send,

§

impl<S, C, M> Sync for Repository<S, C, M>
where M: Sync,

§

impl<S, C, M> Unpin for Repository<S, C, M>
where S: Unpin, M: Unpin, C: Unpin,

§

impl<S, C, M> UnwindSafe for Repository<S, C, M>
where S: UnwindSafe, M: UnwindSafe, C: UnwindSafe,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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