Crates.io | kyval |
lib.rs | kyval |
version | 0.1.2 |
source | src |
created_at | 2024-08-11 04:06:12.865141 |
updated_at | 2024-08-11 09:48:01.983624 |
description | Simple key-value store based on LibSQL. |
homepage | http://github.com/riipandi/kyval |
repository | http://github.com/riipandi/kyval |
max_upload_size | |
id | 1332955 |
size | 51,314 |
Kyval is a simple key-value store based on LibSQL. This project is a fork of Kyval Rust, originally created by Christian Llontop. By utilizing LibSQL, Kyval offers a lightweight and flexible alternative for simple data storage needs.
Main changes: The primary difference between Kyval and the original Kyval Rust is the use of LibSQL as the database backend, replacing SQLite. This change enables Kyval to have improved flexibility in data storage.
cargo add kyval
use kyval::Kyval;
#[tokio::main]
async fn main() {
let kyval_store = KyvalStoreBuilder::new()
.uri(":memory:")
.table_name("kv_store")
.build()
.await.unwrap();
let keyv = Kyval::try_new(kyval_store).await.unwrap();
kyval.set("number", 42).await.unwrap();
kyval.set("number", 10).await.unwrap();
kyval.set("array", vec!["hola", "test"]).await.unwrap();
kyval.set("string", "life long").await.unwrap();
match kyval.get("number").await.unwrap() {
Some(number) => {
let number: i32 = serde_json::from_value(number).unwrap();
assert_eq!(number, 10);
}
None => assert!(false),
}
match kyval.get("string").await.unwrap() {
Some(string) => {
let string: String = serde_json::from_value(string).unwrap();
assert_eq!(string, "life long");
}
None => assert!(false),
}
match kyval.get("array").await.unwrap() {
Some(array) => {
let array: Vec<String> = serde_json::from_value(array).unwrap();
assert_eq!(array, vec!["hola".to_string(), "test".to_string()])
}
None => assert!(false),
}
match kyval.remove_many(&["number", "string"]).await {
Ok(_) => {}
Err(_) => assert!(false),
}
}
Licensed under either of Apache License 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution
intentionally submitted for inclusion in this project by you,
as defined in the Apache-2.0 license, shall be dual licensed
as above, without any additional terms or conditions.
Copyrights in this project are retained by their contributors.
See the LICENSE-APACHE and LICENSE-MIT files for more information.
🤫 Psst! If you like our work you can support us via GitHub sponsors.