pub struct Collection { /* private fields */ }Expand description
Group of items in the database
Implementations§
Source§impl Collection
impl Collection
Sourcepub fn get_all<T>(&self) -> Result<Vec<Item<T>>, Error>where
for<'de> T: Deserialize<'de>,
pub fn get_all<T>(&self) -> Result<Vec<Item<T>>, Error>where
for<'de> T: Deserialize<'de>,
Get all the items in the collection
Sourcepub fn find_many<T, F>(&self, f: F) -> Result<Vec<Item<T>>, Error>
pub fn find_many<T, F>(&self, f: F) -> Result<Vec<Item<T>>, Error>
Get a subset of the items in the collection
Items are filtered by the function f, which is passed an
Item and should return true to include that Item in the
results, or false to exclude it from the results.
Sourcepub fn get_one<T>(&self, id: &Id) -> Result<Item<T>, Error>where
for<'de> T: Deserialize<'de>,
pub fn get_one<T>(&self, id: &Id) -> Result<Item<T>, Error>where
for<'de> T: Deserialize<'de>,
Get one item by its ID
Sourcepub fn insert_one<T>(&self, data: &T) -> Result<Id, Error>where
T: Serialize,
pub fn insert_one<T>(&self, data: &T) -> Result<Id, Error>where
T: Serialize,
Insert one item into the collection
A unique ID will be generated for the item and returned.
Sourcepub fn replace_one<T>(&self, item: &Item<T>) -> Result<(), Error>where
T: Serialize,
pub fn replace_one<T>(&self, item: &Item<T>) -> Result<(), Error>where
T: Serialize,
Overwrite one item in the collection
Sourcepub fn update_by_id<T, U>(&self, id: &Id, u: U) -> Result<(), Error>
pub fn update_by_id<T, U>(&self, id: &Id, u: U) -> Result<(), Error>
Find an item by its ID and update it
If the item is found, the function u will be called with
that item. The function can modify the data as needed, and the
new item will be written to the collection. Note that the ID
cannot be modified.
Sourcepub fn update_many<T, F, U>(&self, f: F, u: U) -> Result<(), Error>
pub fn update_many<T, F, U>(&self, f: F, u: U) -> Result<(), Error>
Update a subset of the items in the collection
For each item in the collection the function f is called
with that item. The function should return true to update
the item or false to leave it unmodified. For each item
where f returned true, the function u is called to
update the item. The function can modify the data as needed,
and the new item will be written to the collection. Note that
the ID cannot be modified.
Trait Implementations§
Source§impl Clone for Collection
impl Clone for Collection
Source§fn clone(&self) -> Collection
fn clone(&self) -> Collection
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more