Skip to content

Commit

Permalink
Added example from readme
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 committed Oct 15, 2020
1 parent c7a36d3 commit eb3ea8b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions examples/temp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use unqlite::{UnQLite, KV, Cursor};

fn main() {
// The database memory is not handled by Rust, and the database is on-disk,
// so `mut` is not neccessary.
let unqlite = UnQLite::create_temp();
// Use any type that can use as `[u8]`
unqlite.kv_store("key", "a long length value").unwrap();
unqlite.kv_store("abc", [1,2,3]).unwrap();

let mut entry = unqlite.first();
// Iterate records
loop {
if entry.is_none() { break; }

let record = entry.expect("valid entry");
let (key, value) = record.key_value();
println!("* Go through {:?} --> {:?}", key, value);

if value.len() > 10 {
println!("** Delete key {:?} by value length", key);
entry = record.delete();
} else {
entry = record.next();
}
}

}

0 comments on commit eb3ea8b

Please sign in to comment.