package lmdb

  1. Overview
  2. Docs

OCaml binding for LMDB.

The LMDB database is a fast in-file database that supports ACID transactions.

These bindings attempts to expose a typesafe yet low-overhead API.

First, an environment must be open using Env.create:

let env = Env.create "mydb" 

Database implementations are specialized both by keys and values and answer the S signature. Two module are predefined:

  • Db uses string keys and string values.
  • IntDb uses int keys and string values.

Using Db, we can open a new database and add our first value:

let db = Db.create ~create:true env "Camelidae" in
Db.put db "Bactrian camel" "Elegant and beautiful animal with two humps."

Transactions and Iterators are also available.

You can define new database implementations using the Make functor.

Environments

module Env : sig ... end

Operations on environment.

Databases

module PutFlags : sig ... end

Flags usable with the put operation.

module type S = sig ... end

Main signature for a database module.

module Db : S with type key = string and type elt = string

Database with string keys and string elements.

module IntDb : S with type key = int and type elt = string

Database with integer keys and string elements.

Error reporting

type error = int

Error return code. See Lmdb's documentation for details.

exception Error of error

Error are reported with this exception or with Not_found.

val pp_error : Format.formatter -> error -> unit

pp_error Format.std_formatter e will print a human-readable description of the given error.

Databases with custom datatypes

module Values : sig ... end
module Make (Key : Values.S) (Elt : Values.S) : S with type key = Key.t and type elt = Elt.t
val version : unit -> string * int * int * int