package lmdb

  1. Overview
  2. Docs

A series of operation performed atomically.

type 'a txn constraint 'a = [< `Read | `Write ]

A transaction handle. A transaction may be read-only or read-write.

val go : ?parent:[< `Read | `Write ] as 'a txn -> rw:'a -> t -> ('a txn -> 'b) -> 'b option

go ~rw db f makes a transaction in db with the permission rw and using the function f.

The function f will receive the transaction handle. All the operations called using the Txn module will be executed when f returns. The transaction handle should not be leaked outside of f.

Return None if the transaction was aborted with abort, and Some v otherwise.

Here is an example incrementing a value atomically:

go ~rw:`Write db begin fun txn ->
  let v = get k in
  put k (v+1) ;
  v
end
val abort : 'a txn -> 'b

abort txn will abort the transaction.

val get : 'a txn -> key -> elt

get txn k returns the value associated to k.

  • raises Not_found

    if the key is not in the database.

val put : ?flags:PutFlags.t -> [> `Write ] txn -> key -> elt -> unit

put txn k v associates the key k to the value v.

  • parameter flags

    Flags that allow to modify the behavior of put.

val append : [> `Write ] txn -> key -> elt -> unit

append txn k v append k, v at the end of the database without performing comparisons.

Should only be used to quickly add already-sorted data to the database.

val remove : ?elt:elt -> [> `Write ] txn -> key -> unit

remove txn k removes k from the database.

If the database accepts duplicates:

  • if elt is provided, only the specified binding is removed.
  • if elt is not provided, all the bindings with k are removed.

Misc

val env : 'a txn -> Env.t
val stats : 'a txn -> Env.stats
val compare : 'a txn -> key -> key -> int

The comparison function used by the database.

val drop : ?delete:bool -> [< `Write ] txn -> unit
OCaml

Innovation. Community. Security.