Crate kv[−][src]
kv
is a simple way to embed a key/value store in Rust applications. It is build on LMDB and
aims to be as lightweight as possible, while still providing a nice high level interface.
Getting started
extern crate kv; use kv::{Config, Error, Manager, ValueRef}; fn run() -> Result<(), Error> { // First step create a manager, this ensured that each LMDB environment will only be // accessed once per process let mut mgr = Manager::new(); // Next configure a database let mut cfg = Config::default("/tmp/rust-kv"); // Add a bucket named `test` cfg.bucket("test", None); // Get a Store handle let handle = mgr.open(cfg)?; // Get read-write access to the underlying store let store = handle.write()?; // A Bucket provides typed access to an LMDB database let bucket = store.bucket::<&str, &str>(Some("test"))?; { // Finally, a transaction is needed, they can be read-write or readonly, here we will use a // write transaction to add data let mut txn = store.write_txn()?; // To set a value let () = txn.set(&bucket, "testing", "abc123")?; // Make sure to commit the transaction. There is also an `abort` function to abandon // the transaction txn.commit()?; } { // This time a readonly transaction let txn = store.read_txn()?; // Getting a value is easy once everything is set up let val = txn.get(&bucket, "testing")?; println!("testing => {}", val); } Ok(()) }
Structs
Bucket |
A Bucket represents a single database, or section of the Store |
Config |
Config is used to create a new store |
DatabaseFlags |
Database options. |
Integer |
Integer key type |
Manager |
A process is only permitted to have one open handle to each database. This manager exists to enforce that constraint: don't open databases directly. |
Store |
A Store is used to keep data on disk using LMDB |
ValueBuf |
A Value can be used to dynamically build values |
ValueMut |
A mutable reference to an existing value slice |
ValueRef |
A reference to an existing value slice |
Enums
Cursor |
Iterable access to the database |
CursorOp |
CursorOp provides the ability to specify the position of a cursor |
Error |
Error type |
Txn |
Access to the database |
Traits
Encoding |
Encoded values |
Key |
A Key can be used as a key to a database |
Serde |
A trait for types wrapping Serde values |
Value |
A Value can be stored in a database |