pub struct Repository<T, Store>{ /* private fields */ }
Expand description
Implementation of the Repository pattern for storing, retrieving
and deleting Aggregate
s.
A Repository
instruments an EventStore
to:
- Insert
Event
s in theEventStore
for an Aggregate, using theAggregateRoot
, - Get all the
Event
s in theEventStore
and rebuild theState
of an Aggregate, into a newAggregateRoot
instance, - Remove all the
Event
s for an Aggregate in theEventStore
.
Implementations§
Source§impl<T, Store> Repository<T, Store>
impl<T, Store> Repository<T, Store>
Sourcepub fn new(builder: AggregateRootBuilder<T>, store: Store) -> Self
pub fn new(builder: AggregateRootBuilder<T>, store: Store) -> Self
Creates a new Repository
instance, using the Aggregate
and EventStore
provided.
Source§impl<T, Store> Repository<T, Store>
impl<T, Store> Repository<T, Store>
Sourcepub async fn get(&self, id: T::Id) -> Result<AggregateRoot<T>, T, Store>
pub async fn get(&self, id: T::Id) -> Result<AggregateRoot<T>, T, Store>
Returns the Aggregate
from the Repository
with the specified id,
if any.
In case the Aggregate
with the specified id exists, returns
a new AggregateRoot
instance with its latest State
.
Otherwise, None
is returned.
Sourcepub async fn add(
&mut self,
root: AggregateRoot<T>,
) -> Result<AggregateRoot<T>, T, Store>
pub async fn add( &mut self, root: AggregateRoot<T>, ) -> Result<AggregateRoot<T>, T, Store>
Adds a new State
of the Aggregate
into the Repository
,
through an AggregateRoot
instance.
Returns Error::NoEvents
if there are no Event
s to commit
in the AggregateRoot
.
Trait Implementations§
Source§impl<T, Store> Clone for Repository<T, Store>
impl<T, Store> Clone for Repository<T, Store>
Source§fn clone(&self) -> Repository<T, Store>
fn clone(&self) -> Repository<T, Store>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl<T, Store> Freeze for Repository<T, Store>
impl<T, Store> RefUnwindSafe for Repository<T, Store>where
Store: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, Store> Send for Repository<T, Store>
impl<T, Store> Sync for Repository<T, Store>
impl<T, Store> Unpin for Repository<T, Store>
impl<T, Store> UnwindSafe for Repository<T, Store>where
Store: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more