shriphani / clj-lmdb

Clojure wrapper for lmdb

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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")))))

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.

About

Clojure wrapper for lmdb

License:Eclipse Public License 1.0


Languages

Language:Clojure 100.0%