#persistence #rocksdb #bincode #serialization #automatic #wrapper

rocksbin

A simple rocksdb wrapper using serde and bincode for automatic serialization

4 releases (2 breaking)

Uses old Rust 2015

0.3.0 Jan 31, 2019
0.2.0 Dec 23, 2018
0.1.1 Dec 4, 2018
0.1.0 Nov 28, 2018

#31 in #bincode

MIT license

19KB
301 lines

Rocksbin-db

Build Status Crates.io Documentation GitHub license

A simple rust rocksdb wrapper using serde and bincode for automatic serialization.

This library is perfect if what you want is a persistent HashMap stored on disk and a simple API.

extern crate rocksbin;

use rocksbin::DB;

let db = DB::open("db_dir").unwrap();

let fish_count = db.prefix::<String, u64>(b"fish_count").unwarp();

fish_count.insert("salmon", 10).unwarp();
fish_count.insert("cod", 100).unwarp();
fish_count.insert("mackerel", 70).unwarp();

assert_eq!(fish_count.get("salmon").unwarp(), Some(10));

lib.rs:

rocksbin-db is a simple library wrapping rocksdb in an interface mimicing rust collections like HashMap.

It does this by utilising serde and bincode to automaticly serialize data you enter into the database.

Examples

#[macro_use]
extern crate serde_derive;

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
struct Fish {
    count: u64,
    latin_name: String,
}

let db = rocksbin::DB::open("db_dir").unwrap();

let fish = db.prefix::<String, Fish>(b"fish").unwrap();

let salmon = Fish {
    count: 100,
    latin_name: "Salmo salar".to_string(),
};

fish.insert("salmon", &salmon);

assert_eq!(fish.get("salmon").unwrap(), Some(salmon));

Dependencies

~26MB
~543K SLoC