Giter VIP home page Giter VIP logo

clj-lmdb's Introduction

clj-lmdb

Circle CI

Clojure wrappers for lmdb - the best no-nonsense, no-surprise, fast key-value store.

Usage

Clojars Project

Creating a database

make-db

(use 'clj-lmdb.simple :reload)
nil
user> (def db (make-db "/tmp"))
#'user/db

You can specify the max memory map size as well:

(use 'clj-lmdb.core :reload)
nil
user> (def db (make-db "/tmp" <size_in_bytes>))
#'user/db

Inserting/Retrieving Values

get! and put!

user> (put! db "foo" "bar")
nil
user> (get! db "foo")
"bar"
user> 

Deleting Values

delete!

user> (delete! db "foo")
true
user> (get! db "foo")
nil
user>

Transactions:

read-txn to create a read-only transaction

write-txn to create a transaction that updates the db

This inserts a couple of entries:

(with-txn [txn (write-txn db)]
  (put! db
        txn
        "foo"
        "bar")
  (put! db
        txn
        "foo1"
        "bar1"))

This retrieves them

(with-txn [txn (read-txn db)]
  (= (get! db
           txn
           "foo")
     "bar") ; true

  (= (get! db
           txn
           "foo1")
     "bar1")) ; true

Iterating through entries:

Inside a read-transaction you can use items or items-from to iterate over the entries or to iterate from a particular key onwards.

(with-txn [txn (read-txn db)]
 (count
  (doall
   (map
    (fn [[k v]]
      ...)
    (items db txn)))))
(with-txn [txn (read-txn db)]
 (count
  (doall
   (map
    (fn [[k v]]
      ...)
    (items-from db txn "foo")))))

Use optional parameters :order :asc or :order :desc (default order is ascending) in items and items-from function calls to specify ascending or descending order of the keys.

(with-txn [txn (read-txn db)]
 (count
  (doall
   (map
    (fn [[k v]]
      ...)
    (items db txn :order :desc)))))
(with-txn [txn (read-txn db)]
 (count
  (doall
   (map
    (fn [[k v]]
      ...)
    (items-from db txn "foo" :order :desc)))))

For more examples, see the tests

LICENSE

Copyright © 2016 Shriphani Palakodety

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

clj-lmdb's People

Contributors

monodeldiablo avatar shriphani avatar t44k 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.