5 releases
0.1.2 | Aug 11, 2024 |
---|---|
0.1.1 | Aug 11, 2024 |
0.1.0 | Aug 11, 2024 |
0.0.2 | Aug 11, 2024 |
0.0.1 | Aug 11, 2024 |
#2927 in Database interfaces
39KB
529 lines
Kyval
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.
Usage
Instalation
cargo add kyval
Interacting with Store
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),
}
}
License
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.
Dependencies
~5–12MB
~136K SLoC