[−][src]Trait domain_patterns::collections::ReadRepository
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.
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>
&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.
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.