pub struct AggregateStore<A: Aggregate> { /* private fields */ }
Expand description

This type is responsible for managing aggregates.

Implementations§

source§

impl<A: Aggregate> AggregateStore<A>

source

pub fn create( storage_uri: &Url, namespace: &Namespace, use_history_cache: bool ) -> StoreResult<Self>

Creates an AggregateStore using the given storage url

source

pub fn create_upgrade_store( storage_uri: &Url, name_space: &Namespace, use_history_cache: bool ) -> StoreResult<Self>

Creates an AggregateStore for upgrades using the given storage url

source

pub fn warm(&self) -> StoreResult<()>

Warms up the cache, to be used after startup. Will fail if any aggregates fail to load.

source

pub fn warm_aggregate(&self, handle: &MyHandle) -> StoreResult<()>

Warm the cache for a specific aggregate.

source

pub fn add_pre_save_listener<L: PreSaveEventListener<A>>( &mut self, sync_listener: Arc<L> )

Adds a listener that will receive all events before they are stored.

source

pub fn add_post_save_listener<L: PostSaveEventListener<A>>( &mut self, listener: Arc<L> )

Adds a listener that will receive a reference to all events after they are stored.

source§

impl<A: Aggregate> AggregateStore<A>

source

pub fn get_latest(&self, handle: &MyHandle) -> Result<Arc<A>, A::Error>

Gets the latest version for the given aggregate. Returns an AggregateStoreError::UnknownAggregate in case the aggregate does not exist.

source

pub fn update_snapshots(&self) -> Result<(), A::Error>

Updates the snapshots for all entities in this store.

source

pub fn save_snapshot(&self, handle: &MyHandle) -> Result<Arc<A>, A::Error>

Gets the latest version for the given aggregate and updates the snapshot.

source

pub fn add(&self, cmd: A::InitCommand) -> Result<Arc<A>, A::Error>

Adds a new aggregate instance based on the init event.

source

pub fn command(&self, cmd: A::Command) -> Result<Arc<A>, A::Error>

Send a command to the latest aggregate referenced by the handle in the command.

This will:

  • Retrieve the latest aggregate for this command.
  • Call the A::process_command function on success:
    • call pre-save listeners with events
    • save command and events
    • call post-save listeners with events
    • return aggregate on no-op (empty event list):
    • do not save anything, return aggregate on error:
    • save command and error, return error
source

pub fn has(&self, id: &MyHandle) -> Result<bool, AggregateStoreError>

Returns true if an instance exists for the id

source

pub fn list(&self) -> Result<Vec<MyHandle>, AggregateStoreError>

Lists all known ids.

source§

impl<A: Aggregate> AggregateStore<A>

source

pub fn command_history( &self, id: &MyHandle, crit: CommandHistoryCriteria ) -> Result<CommandHistory, AggregateStoreError>

Find all commands that fit the criteria and return history

source

pub fn get_command( &self, id: &MyHandle, version: u64 ) -> Result<StoredCommand<A>, AggregateStoreError>

Get the command for this key, if it exists

source§

impl<A: Aggregate> AggregateStore<A>

source

pub fn drop_aggregate(&self, id: &MyHandle) -> Result<(), AggregateStoreError>

Drop an aggregate, completely. Handle with care!

Auto Trait Implementations§

§

impl<A> !RefUnwindSafe for AggregateStore<A>

§

impl<A> Send for AggregateStore<A>

§

impl<A> Sync for AggregateStore<A>

§

impl<A> Unpin for AggregateStore<A>

§

impl<A> !UnwindSafe for AggregateStore<A>

Blanket Implementations§

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.

§

impl<T> Instrument for T

§

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

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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