pub struct Repository<T, Store>where
T: Aggregate + Clone + 'static,
Store: EventStore<SourceId = <T as Aggregate>::Id, Event = <T as Aggregate>::Event>,{ /* 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,
) -> Repository<T, Store>
pub fn new( builder: AggregateRootBuilder<T>, store: Store, ) -> Repository<T, Store>
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 as Aggregate>::Id,
) -> Result<AggregateRoot<T>, Error<<T as Aggregate>::Error, <Store as EventStore>::Error>>
pub async fn get( &self, id: <T as Aggregate>::Id, ) -> Result<AggregateRoot<T>, Error<<T as Aggregate>::Error, <Store as EventStore>::Error>>
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>, Error<<T as Aggregate>::Error, <Store as EventStore>::Error>>
pub async fn add( &mut self, root: AggregateRoot<T>, ) -> Result<AggregateRoot<T>, Error<<T as Aggregate>::Error, <Store as EventStore>::Error>>
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