add find_all

This commit is contained in:
JMARyA 2024-08-13 02:20:32 +02:00
parent c4f2b6eb81
commit 84ef28312e
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263

View file

@ -1,4 +1,5 @@
use mongodb::{
bson::doc,
options::{FindOneOptions, FindOptions},
results::{DeleteResult, InsertOneResult},
};
@ -175,6 +176,20 @@ pub trait Model:
}
}
/// Get all `Model`s from the database
#[must_use]
fn find_all() -> impl std::future::Future<Output = Option<Vec<Self>>> {
Self::find(doc! {}, None)
}
/// Get all `Model`s partial from the database
#[must_use]
fn find_all_partial(
part: serde_json::Value,
) -> impl std::future::Future<Output = Option<Vec<Self::Partial>>> {
Self::find_partial(doc! {}, part, None)
}
/// Get multiple `Model`s by using a filter from the database. Pass a `limit` parameter to limit the amount of `Model`s returned.
#[must_use]
fn find(