pub struct Repository<S, C = Optimistic, M = NoSnapshots<<S as EventStore>::Id, <S as EventStore>::Position>>where
S: EventStore,
C: ConcurrencyStrategy,{ /* private fields */ }Expand description
Repository.
Implementations§
Source§impl<S> Repository<S>where
S: EventStore,
impl<S> Repository<S>where
S: EventStore,
Source§impl<S, M> Repository<S, Optimistic, M>where
S: EventStore,
impl<S, M> Repository<S, Optimistic, M>where
S: EventStore,
Sourcepub fn without_concurrency_checking(self) -> Repository<S, Unchecked, M>
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>where
S: EventStore,
C: ConcurrencyStrategy,
impl<S, C, M> Repository<S, C, M>where
S: EventStore,
C: ConcurrencyStrategy,
pub const fn event_store(&self) -> &S
pub fn build_projection<P>(&self) -> ProjectionBuilder<'_, S, P>where
P: Projection<Id = S::Id>,
pub fn with_snapshots<SS>( self, snapshots: SS, ) -> Repository<S, C, Snapshots<SS>>
Source§impl<S, C> Repository<S, C, NoSnapshots<S::Id, S::Position>>where
S: EventStore,
C: ConcurrencyStrategy,
impl<S, C> Repository<S, C, NoSnapshots<S::Id, S::Position>>where
S: EventStore,
C: ConcurrencyStrategy,
pub const fn aggregate_builder<A>(&self) -> AggregateBuilder<'_, Self, A>
Sourcepub async fn load<A>(
&self,
id: &S::Id,
) -> Result<A, ProjectionError<<S as EventStore>::Error, <<S as EventStore>::Codec as Codec>::Error>>
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 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,
impl<S> Repository<S, Unchecked>where
S: EventStore,
Sourcepub 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,
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,
impl<S> Repository<S, Optimistic>where
S: EventStore,
Sourcepub 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,
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.
Sourcepub 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,
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>>
impl<S, SS, C> Repository<S, C, Snapshots<SS>>
pub const fn snapshot_store(&self) -> &SS
pub const fn aggregate_builder<A>(&self) -> AggregateBuilder<'_, Self, A>
Sourcepub async fn load<A>(
&self,
id: &S::Id,
) -> Result<A, ProjectionError<<S as EventStore>::Error, <<S as EventStore>::Codec as Codec>::Error>>
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>>
impl<S, SS> Repository<S, Unchecked, Snapshots<SS>>
Sourcepub async fn execute_command<A, Cmd>(
&mut self,
id: &S::Id,
command: &Cmd,
metadata: &S::Metadata,
) -> UncheckedSnapshotCommandResult<A, S, SS>where
A: Aggregate<Id = S::Id> + Handle<Cmd> + Serialize + DeserializeOwned,
A::Event: ProjectionEvent + SerializableEvent,
Cmd: Sync,
S::Metadata: Clone,
pub async fn execute_command<A, Cmd>(
&mut self,
id: &S::Id,
command: &Cmd,
metadata: &S::Metadata,
) -> UncheckedSnapshotCommandResult<A, S, SS>where
A: Aggregate<Id = S::Id> + Handle<Cmd> + Serialize + DeserializeOwned,
A::Event: ProjectionEvent + SerializableEvent,
Cmd: Sync,
S::Metadata: Clone,
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>>
impl<S, SS> Repository<S, Optimistic, Snapshots<SS>>
Sourcepub async fn execute_command<A, Cmd>(
&mut self,
id: &S::Id,
command: &Cmd,
metadata: &S::Metadata,
) -> OptimisticSnapshotCommandResult<A, S, SS>where
A: Aggregate<Id = S::Id> + Handle<Cmd> + Serialize + DeserializeOwned,
A::Event: ProjectionEvent + SerializableEvent,
Cmd: Sync,
S::Metadata: Clone,
pub async fn execute_command<A, Cmd>(
&mut self,
id: &S::Id,
command: &Cmd,
metadata: &S::Metadata,
) -> OptimisticSnapshotCommandResult<A, S, SS>where
A: Aggregate<Id = S::Id> + Handle<Cmd> + Serialize + DeserializeOwned,
A::Event: ProjectionEvent + SerializableEvent,
Cmd: Sync,
S::Metadata: Clone,
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.
Sourcepub async fn execute_with_retry<A, Cmd>(
&mut self,
id: &S::Id,
command: &Cmd,
metadata: &S::Metadata,
max_retries: usize,
) -> SnapshotRetryResult<A, S, SS>where
A: Aggregate<Id = S::Id> + Handle<Cmd> + Serialize + DeserializeOwned,
A::Event: ProjectionEvent + SerializableEvent,
Cmd: Sync,
S::Metadata: Clone,
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>where
A: Aggregate<Id = S::Id> + Handle<Cmd> + Serialize + DeserializeOwned,
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.