Crate leveldb

Source
Expand description

A database access library for leveldb

Usage:

extern crate tempdir;
extern crate leveldb;

use tempdir::TempDir;
use leveldb::database::Database;
use leveldb::kv::KV;
use leveldb::options::{Options,WriteOptions,ReadOptions};

let tempdir = TempDir::new("demo").unwrap();
let path = tempdir.path();

let mut options = Options::new();
options.create_if_missing = true;
let mut database = match Database::open(path, options) {
    Ok(db) => { db },
    Err(e) => { panic!("failed to open database: {:?}", e) }
};

let write_opts = WriteOptions::new();
match database.put(write_opts, 1, &[1]) {
    Ok(_) => { () },
    Err(e) => { panic!("failed to write to database: {:?}", e) }
};

let read_opts = ReadOptions::new();
let res = database.get(read_opts, 1);

match res {
  Ok(data) => {
    assert!(data.is_some());
    assert_eq!(data, Some(vec![1]));
  }
  Err(e) => { panic!("failed reading data: {:?}", e) }
}

Re-exports§

Modules§

  • The main database module, allowing to interface with leveldb on a key-value basis.

Traits§