Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update keyv package version to 0.2.0 #28

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(crate) table_name: String,
pub(crate) schema: Option<String>,
}

impl PostgresStore {
fn get_table_name(&self) -> String {
match &self.schema {
Expand All @@ -32,7 +33,7 @@
StoreError::QueryError(format!(
"Failed to create the schema '{}': {}",
schema,
e.to_string()

Check warning on line 36 in src/store/adapter/postgres/postgres.rs

View workflow job for this annotation

GitHub Actions / build

`to_string` applied to a type that implements `Display` in `format!` args
))
})?;
}
Expand All @@ -48,7 +49,7 @@
sqlx::query(&sql).execute(&*self.pool).await.map_err(|e| {
StoreError::QueryError(format!(
"Failed to initialize the database table: {}",
e.to_string()

Check warning on line 52 in src/store/adapter/postgres/postgres.rs

View workflow job for this annotation

GitHub Actions / build

`to_string` applied to a type that implements `Display` in `format!` args
))
})?;

Expand All @@ -63,9 +64,7 @@
.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 @@
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
Loading