Skip to content

Commit

Permalink
fix Clippy warnings and update some libs.
Browse files Browse the repository at this point in the history
  • Loading branch information
genusistimelord committed Aug 13, 2024
1 parent aa85b27 commit 0dd00ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
38 changes: 14 additions & 24 deletions databases/mongo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<MongoSessionData>(table_name);

let _ = &col
Expand All @@ -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<Vec<String>, DatabaseError> {
let mut ids: Vec<String> = 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}
Expand All @@ -91,8 +90,7 @@ impl DatabasePool for SessionMongoPool {
.await
.map_err(|err| DatabaseError::GenericDeleteError(err.to_string()))?;
}
None => {}
}

Ok(ids)
}

Expand All @@ -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
};
Expand All @@ -132,8 +129,7 @@ impl DatabasePool for SessionMongoPool {
.await
.map_err(|err| DatabaseError::GenericInsertError(err.to_string()))?;
}
None => {}
}

Ok(())
}

Expand Down Expand Up @@ -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::<MongoSessionData>(table_name)
.delete_one(doc! {"id": id})
.await
.map_err(|err| DatabaseError::GenericDeleteError(err.to_string()))?;
}
None => {}
}

Ok(())
}

Expand All @@ -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::<MongoSessionData>(table_name)
.drop()
.await
.map_err(|err| DatabaseError::GenericDeleteError(err.to_string()))?;
}
None => {}
}

Ok(())
}

async fn get_ids(&self, table_name: &str) -> Result<Vec<String>, DatabaseError> {
let mut ids: Vec<String> = 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()}
};
Expand All @@ -224,8 +215,7 @@ impl DatabasePool for SessionMongoPool {
};
}
}
None => {}
}

Ok(ids)
}

Expand Down
4 changes: 2 additions & 2 deletions databases/sqlx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0dd00ab

Please sign in to comment.