[−][src]Struct ipjdb::Collection
Group of items in the database
Methods
impl Collection
[src]
pub fn get_all<T>(&self) -> Result<Vec<Item<T>>, DbError> where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
Get all the items in the collection
pub fn find_many<T, F>(&self, f: F) -> Result<Vec<Item<T>>, DbError> where
T: Deserialize<'de>,
F: Fn(&Item<T>) -> bool,
[src]
T: Deserialize<'de>,
F: Fn(&Item<T>) -> bool,
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.
pub fn get_one<T>(&self, id: &Id) -> Result<Item<T>, DbError> where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
Get one item by its ID
pub fn insert_one<T>(&self, data: &T) -> Result<Id, DbError> where
T: Serialize,
[src]
T: Serialize,
Insert one item into the collection
A unique ID will be generated for the item and returned.
pub fn delete_one(&self, id: &Id) -> Result<(), DbError>
[src]
Delete one item from the collection
pub fn replace_one<T>(&self, item: &Item<T>) -> Result<(), DbError> where
T: Serialize,
[src]
T: Serialize,
Overwrite one item in the collection
pub fn update_by_id<T, U>(&self, id: &Id, u: U) -> Result<(), DbError> where
T: Deserialize<'de> + Serialize,
U: Fn(&mut Item<T>),
[src]
T: Deserialize<'de> + Serialize,
U: Fn(&mut Item<T>),
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.
pub fn update_many<T, F, U>(&self, f: F, u: U) -> Result<(), DbError> where
T: Deserialize<'de> + Serialize,
F: Fn(&Item<T>) -> bool,
U: Fn(&mut Item<T>),
[src]
T: Deserialize<'de> + Serialize,
F: Fn(&Item<T>) -> bool,
U: Fn(&mut Item<T>),
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
Auto Trait Implementations
impl Send for Collection
impl Sync for Collection
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,