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

pub trait ReadRepository<T> {
    type Error: Error + Display + 'static + Send;
    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 likely a DTO used for pure data transfer to an external caller, whether that's via a REST controller or over gRPC as a proto type etc.

Associated Types

type Error: Error + Display + 'static + Send

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