Expand description

An ORM wrapper for Rust leveldb leveldb::database::kv::KV APIs. Use bincode to encoder / decoder key and object.

Example

This example shows the quickest way to get started with feature macros

[dependencies]
leveldb = "0.8"
leveldb-orm = { version = "0.1", features = ["macros"]}
serde = { version = "1.0", features = ["derive"] }
use leveldb::database::Database;
use leveldb::options::Options;
use leveldb_orm::{KVOrm, KeyOrm, LevelDBOrm};
use serde::{Deserialize, Serialize};
 
#[derive(LevelDBOrm, Serialize, Deserialize)]
#[level_db_key(executable, args)]
pub struct Command {
    pub executable: u8,
    pub args: Vec<String>,
    pub current_dir: Option<String>,
}
 
let cmd = Command {
    executable: 1,
    args: vec!["arg1".into(), "arg2".into(), "arg3".into()],
    current_dir: Some("\\dir".into()),
};
 
let mut options = Options::new();
options.create_if_missing = true;
let database = Database::open(std::path::Path::new("./mypath"), options).unwrap();
 
cmd.put(&database).unwrap();
 
let key = Command::encode_key((&cmd.executable, &cmd.args)).unwrap();
// or `let key = cmd.key().unwrap();`
Command::get(&database, &key).unwrap();
 
Command::delete(&database, false, &key).unwrap();

Structs

The key for leveldb, which impled db_key::Key. (db-key 0.0.5 only impl it for i32) You can serialize you key to Vec / &[u8] and into EncodedKey.

Traits

Interface of key encode / decode