package lmdb

  1. Overview
  2. Docs

Manual iterators.

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

A cursor allows to iterates manually on the database. A cursor may be read-only or read-write.

val go : 'cap Txn.txn -> f:('cap t -> 'a) -> 'a

go txn f makes a cursor in the transaction txn using the function f.

The function f will receive the cursor. A cursor can only be create and used inside a transaction. The cursor inherits the permissions of the transaction. The cursor should not be leaked outside of f.

Here is an example that returns the first 5 elements of a database:

go txn begin fun c ->
  let h = first c in
  let rec aux i =
    if i < 5 then next c :: aux (i+1)
    else []
  in
  h :: aux 1
end
val get : _ t -> key * elt

get cursor returns the binding at the position of the cursor.

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

put cursor k v adds k,v to the database and move the cursor to its position.

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

put_here cursor k v adds k,v at the current position.

  • raises Error

    if the key provided is not the current key.

val remove : ?all:bool -> [> `Write ] t -> unit

remove cursor removes the current binding.

If the database allow duplicate keys and if all is true, removes all the bindings associated to the current key.

val first : _ t -> key * elt

first cursor moves the cursor to the first binding.

val last : _ t -> key * elt

last cursor moves the cursor to the last binding.

val next : _ t -> key * elt

next cursor moves the cursor to the next binding.

val prev : _ t -> key * elt

prev cursor moves the cursor to the prev binding.

val seek : _ t -> key -> elt

seek cursor k moves the cursor to the key k.

val seek_range : _ t -> key -> elt

seek_range cursor k moves the cursor to the first key greater or equal to k.

Operations on duplicated keys

Similar to the previous operations, but only inside a set of binding sharing the same key.

Raise Invalid_argument if used on a database that does not support duplicate keys.

val first_dup : _ t -> key * elt
val last_dup : _ t -> key * elt
val next_dup : _ t -> key * elt
val prev_dup : _ t -> key * elt
val seek_dup : _ t -> key -> elt
val seek_range_dup : _ t -> key -> elt
OCaml

Innovation. Community. Security.