kyval

Crates.iokyval
lib.rskyval
version0.1.2
sourcesrc
created_at2024-08-11 04:06:12.865141
updated_at2024-08-11 09:48:01.983624
descriptionSimple key-value store based on LibSQL.
homepagehttp://github.com/riipandi/kyval
repositoryhttp://github.com/riipandi/kyval
max_upload_size
id1332955
size51,314
Aris Ripandi (riipandi)

documentation

https://docs.rs/kyval

README

Kyval

Crates version Rust version Crates.io Total Downloads Contribution welcome


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.

Made by

Commit count: 0

cargo fmt