Code Monkey home page Code Monkey logo

rust-kv's Introduction

kv

An embedded key/value store for Rust built on LMDB

  • Easy configuration
  • Integer keys
  • Serde integration (see the Encoding trait)

Optional features

  • cbor-value
    • CBOR value encoding using serde
  • json-value
    • JSON value encoding using serde
  • bincode-value
    • bincode value encoding using serde

Documentation

See https://docs.rs/kv

Examples

// Create the default configuration
let mut cfg = Config::default(path);

// Load configuration from a TOML file
let mut cfg = Config::load("test.conf");

// Add a bucket named `test`
cfg.bucket("test", None);

// Create a manager
// Managers are used to ensure that each process only has access to one LMDB environment
// reference at a time
let mut mgr = Manager::new();

// Get a Store handle
let handle = mgr.open(cfg).unwrap();

// Get acess to the underlying store
let store = handle.write().unwrap();

// Load a bucket
//
// A reference to a bucket will be the first argument to all functions that
// read or write to the database
let bucket = store.bucket::<&str, &str>(Some("test")).unwrap();

/// Write a value to the store
let mut txn = store.write_txn().unwrap();
txn.set(&bucket, "testing", "abc123").unwrap();

// Don't forget to commit the transaction
txn.commit().unwrap();

/// Read a value
let txn = store.read_txn().unwrap();
let val = txn.get(&bucket, "testing").unwrap();
println!("testing => {}", val);

// You can also abort a transaction
txn.abort();

rust-kv's People

Contributors

zshipko avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.