diff --git a/src/db/bots.rs b/src/db/bots.rs index fc9a632..8b4a005 100644 --- a/src/db/bots.rs +++ b/src/db/bots.rs @@ -43,19 +43,23 @@ impl BotInstance { Ok(self) }); - pub async fn get_all(db: &mut D) -> DbResult> { + pub async fn get_all(db: &mut D) -> DbResult> { let bi = db.get_collection::().await; Ok(bi.find(doc! {}).await?.try_collect().await?) } - pub async fn get_by_name(db: &mut D, name: &str) -> DbResult> { + pub async fn get_by_name(db: &mut D, name: &str) -> DbResult> { let bi = db.get_collection::().await; Ok(bi.find_one(doc! {"name": name}).await?) } - pub async fn restart_one(db: &mut D, name: &str, restart: bool) -> DbResult<()> { + pub async fn restart_one( + db: &mut D, + name: &str, + restart: bool, + ) -> DbResult<()> { let bi = db.get_collection::().await; bi.update_one( @@ -66,7 +70,7 @@ impl BotInstance { Ok(()) } - pub async fn restart_all(db: &mut D, restart: bool) -> DbResult<()> { + pub async fn restart_all(db: &mut D, restart: bool) -> DbResult<()> { let bi = db.get_collection::().await; bi.update_many(doc! {}, doc! { "$set": { "restart_flag": restart } }) @@ -74,7 +78,11 @@ impl BotInstance { Ok(()) } - pub async fn update_script(db: &mut D, name: &str, script: &str) -> DbResult<()> { + pub async fn update_script( + db: &mut D, + name: &str, + script: &str, + ) -> DbResult<()> { let bi = db.get_collection::().await; bi.update_one( diff --git a/src/db/mod.rs b/src/db/mod.rs index 01b1882..442d2cf 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -11,7 +11,6 @@ use chrono::{DateTime, Local, Utc}; use enum_stringify::EnumStringify; use futures::stream::TryStreamExt; -use futures::StreamExt; use mongodb::bson::serde_helpers::chrono_datetime_as_bson_datetime; use mongodb::options::IndexOptions; use mongodb::{bson::doc, options::ClientOptions, Client}; @@ -57,7 +56,7 @@ macro_rules! query_call { #[macro_export] macro_rules! query_call_consume { ($func_name:ident, $self:ident, $db:ident, $return_type:ty, $body:block) => { - pub async fn $func_name($self, $db: &mut D) + pub async fn $func_name($self, $db: &mut D) -> DbResult<$return_type> $body }; } @@ -207,6 +206,7 @@ pub trait DbCollection { const COLLECTION: &str; } +#[async_trait] pub trait GetCollection { async fn get_collection(&mut self) -> Collection; } @@ -222,7 +222,8 @@ impl CallDB for DB { } } -impl GetCollection for T { +#[async_trait] +impl GetCollection for T { async fn get_collection(&mut self) -> Collection { self.get_database() .await