[][src]Trait domain_patterns::collections::ReadRepository

pub trait ReadRepository<T: AggregateRoot> {
    type Error: Error + Display + 'static;
    fn get(&mut self, key: &String) -> Result<Option<T>, Self::Error>;
fn get_paged(
        &mut self,
        page_num: usize,
        page_size: usize
    ) -> Result<Option<Vec<T>>, Self::Error>; fn contains_key(&mut self, key: &String) -> Result<bool, Self::Error> { ... } }

A trait that provides a collection like abstraction over read only database access.

Generic T is some struct that implements Entity<K> where K is used as the key in the repository methods. In other words it's expected that an entities id is used as the key for insert and retrieval.

Associated Types

type Error: Error + Display + 'static

An error that communicates that something went wrong at the database level.

Loading content...

Required methods

fn get(&mut self, key: &String) -> Result<Option<T>, Self::Error>

Returns the entity corresponding to the supplied key as an owned type.

Failure case

If we fail to communicate with the underlying storage, then an error is returned.

fn get_paged(
    &mut self,
    page_num: usize,
    page_size: usize
) -> Result<Option<Vec<T>>, Self::Error>

Returns a Vec<T> of entities, based on the supplied page_num and page_size. The page_num should start at 1, but is up to the implementer to design as they see fit.

Failure case

If we fail to communicate with the underlying storage, then an error is returned.

Loading content...

Provided methods

fn contains_key(&mut self, key: &String) -> Result<bool, Self::Error>

Returns true if the underlying storage contains an entity at the specified key, and otherwise returns false.

Failure case

If we fail to communicate with the underlying storage, then an error is returned.

Loading content...

Implementors

Loading content...