nikidb

Crates.ionikidb
lib.rsnikidb
version0.1.1
sourcesrc
created_at2022-07-12 15:32:35.461874
updated_at2022-07-12 16:01:52.521613
descriptionan embedded k-v storage written in rust, similar to boltdb
homepagehttps://github.com/szuwgh/nikidb
repositoryhttps://github.com/szuwgh/nikidb
max_upload_size
id624464
size113,484
Walter Wu (szuwgh)

documentation

README

nikidb

An embedded B+ tree-based persistent kv storage written in rust, similar to boltdb

example

use nikidb::db::DB;
use nikidb::db::DEFAULT_OPTIONS;
use nikidb::error::{NKError, NKResult};
use nikidb::tx::Tx;
use std::str;

fn main() {
    let db = DB::open("./test.db", DEFAULT_OPTIONS).unwrap();

    //create bucket
    db.update(Box::new(|tx: &mut Tx| -> NKResult<()> {
        match tx.create_bucket("default".as_bytes()) {
            Ok(_) => println!("create default bucket success"),
            Err(NKError::ErrBucketExists(e)) => println!("{} bucket exist", e),
            Err(e) => panic!("create bucket error"),
        }
        Ok(())
    }))
    .unwrap();

    //set key value
    db.update(Box::new(|tx: &mut Tx| -> NKResult<()> {
        let b = tx.bucket("default".as_bytes())?;
        b.put(b"abc", b"123").unwrap();
        Ok(())
    }))
    .unwrap();

    //get key value
    db.view(Box::new(|tx: &mut Tx| -> NKResult<()> {
        let b = tx.bucket("default".as_bytes())?;
        let v = b.get(b"abc").unwrap();
        println!("value:{:?}", str::from_utf8(v).unwrap());
        Ok(())
    }))
    .unwrap();
}
Commit count: 139

cargo fmt