Skip to content

Commit

Permalink
Update keyv package version to 0.2.0 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisllontop authored Apr 18, 2024
2 parents f5f9b93 + 7ab94d7 commit e603f89
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "keyv"
version = "0.1.0"
version = "0.2.0"
authors = ["Christian Llontop <chrisllontop@icloud.com>"]
edition = "2021"
description = "Simple key-value storage with support for multiple backends"
Expand Down
12 changes: 6 additions & 6 deletions src/store/adapter/inmemory/inmemory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ impl Store for InMemoryStore {
Ok(())
}

async fn clear(&self) -> Result<(), StoreError> {
let mut db_lock = self.db.lock().await;
db_lock.clear();
Ok(())
}

async fn remove_many(&self, keys: &[&str]) -> Result<(), StoreError> {
let mut db_lock = self.db.lock().await;
for key in keys {
db_lock.remove(&key.to_string());
}
Ok(())
}

async fn clear(&self) -> Result<(), StoreError> {
let mut db_lock = self.db.lock().await;
db_lock.clear();
Ok(())
}
}
4 changes: 1 addition & 3 deletions src/store/adapter/mysql/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ impl Store for MySqlStore {
.await
.map_err(|_| StoreError::QueryError("Failed to fetch the value".to_string()))?;

Ok(result
.map(|row| serde_json::from_str(row.get("value")).ok())
.flatten())
Ok(result.and_then(|row| serde_json::from_str(row.get("value")).ok()))
}

async fn set(&self, key: &str, value: Value, ttl: Option<u64>) -> Result<(), StoreError> {
Expand Down
7 changes: 3 additions & 4 deletions src/store/adapter/postgres/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct PostgresStore {
pub(crate) table_name: String,
pub(crate) schema: Option<String>,
}

impl PostgresStore {
fn get_table_name(&self) -> String {
match &self.schema {
Expand Down Expand Up @@ -63,9 +64,7 @@ impl Store for PostgresStore {
.await
.map_err(|_| StoreError::QueryError("Failed to fetch the value".to_string()))?;

Ok(result
.map(|row| serde_json::from_str(row.get("value")).ok())
.flatten())
Ok(result.and_then(|row| serde_json::from_str(row.get("value")).ok()))
}

async fn set(&self, key: &str, value: Value, ttl: Option<u64>) -> Result<(), StoreError> {
Expand Down Expand Up @@ -105,7 +104,7 @@ impl Store for PostgresStore {
let query = format!("DELETE FROM {} WHERE key = ANY($1)", self.get_table_name());

sqlx::query(&query)
.bind(&keys)
.bind(keys)
.execute(&*self.pool)
.await
.map_err(|_| StoreError::QueryError("Failed to remove the keys".to_string()))?;
Expand Down

0 comments on commit e603f89

Please sign in to comment.