From 0dd00ab5e0d70b63b12714338b26c8a99d9d3145 Mon Sep 17 00:00:00 2001 From: genusistimelord Date: Tue, 13 Aug 2024 10:12:47 -0400 Subject: [PATCH] fix Clippy warnings and update some libs. --- databases/mongo/src/lib.rs | 38 ++++++++++++++------------------------ databases/sqlx/Cargo.toml | 4 ++-- 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/databases/mongo/src/lib.rs b/databases/mongo/src/lib.rs index a13645c..bb0ad6a 100644 --- a/databases/mongo/src/lib.rs +++ b/databases/mongo/src/lib.rs @@ -49,8 +49,8 @@ impl DatabasePool for SessionMongoPool { // by inserting a record then deleting it async fn initiate(&self, table_name: &str) -> Result<(), DatabaseError> { let tmp = MongoSessionData::default(); - match &self.client.default_database() { - Some(db) => { + + if let Some(db) = &self.client.default_database() { let col = db.collection::(table_name); let _ = &col @@ -62,15 +62,14 @@ impl DatabasePool for SessionMongoPool { .await .map_err(|err| DatabaseError::GenericDeleteError(err.to_string()))?; } - None => {} - } + Ok(()) } async fn delete_by_expiry(&self, table_name: &str) -> Result, DatabaseError> { let mut ids: Vec = Vec::new(); - match &self.client.default_database() { - Some(db) => { + + if let Some(db) = &self.client.default_database() { let now = Utc::now().timestamp(); let filter = doc! {"expires": {"$lte": now} @@ -91,8 +90,7 @@ impl DatabasePool for SessionMongoPool { .await .map_err(|err| DatabaseError::GenericDeleteError(err.to_string()))?; } - None => {} - } + Ok(ids) } @@ -115,8 +113,7 @@ impl DatabasePool for SessionMongoPool { expires: i64, table_name: &str, ) -> Result<(), DatabaseError> { - match &self.client.default_database() { - Some(db) => { + if let Some(db) = &self.client.default_database() { let filter = doc! { "id": id }; @@ -132,8 +129,7 @@ impl DatabasePool for SessionMongoPool { .await .map_err(|err| DatabaseError::GenericInsertError(err.to_string()))?; } - None => {} - } + Ok(()) } @@ -166,16 +162,14 @@ impl DatabasePool for SessionMongoPool { } async fn delete_one_by_id(&self, id: &str, table_name: &str) -> Result<(), DatabaseError> { - match &self.client.default_database() { - Some(db) => { + if let Some(db) = &self.client.default_database() { let _ = db .collection::(table_name) .delete_one(doc! {"id": id}) .await .map_err(|err| DatabaseError::GenericDeleteError(err.to_string()))?; } - None => {} - } + Ok(()) } @@ -192,23 +186,20 @@ impl DatabasePool for SessionMongoPool { } async fn delete_all(&self, table_name: &str) -> Result<(), DatabaseError> { - match &self.client.default_database() { - Some(db) => { + if let Some(db) = &self.client.default_database() { let _ = db .collection::(table_name) .drop() .await .map_err(|err| DatabaseError::GenericDeleteError(err.to_string()))?; } - None => {} - } + Ok(()) } async fn get_ids(&self, table_name: &str) -> Result, DatabaseError> { let mut ids: Vec = Vec::new(); - match &self.client.default_database() { - Some(db) => { + if let Some(db) = &self.client.default_database() { let filter = doc! {"expires": {"$gte": Utc::now().timestamp()} }; @@ -224,8 +215,7 @@ impl DatabasePool for SessionMongoPool { }; } } - None => {} - } + Ok(ids) } diff --git a/databases/sqlx/Cargo.toml b/databases/sqlx/Cargo.toml index 942661c..d70752e 100644 --- a/databases/sqlx/Cargo.toml +++ b/databases/sqlx/Cargo.toml @@ -30,10 +30,10 @@ axum_session.workspace = true [dev-dependencies] axum = { version = "0.7.4", features = ["macros"] } -hyper = "1.2.0" +hyper = "1.4.1" tower = "0.4.13" log = { version = "0.4.20", default-features = false } -http-body-util = "0.1.0" +http-body-util = "0.1.2" sqlx = { version = "0.8.0", default-features = false, features = [ "runtime-tokio", "chrono",