Module Lmdb.Map

Key-value maps.

type ('key, 'value, -'dup) t constraint 'perm = [< `Read | `Write ] constraint 'dup = [< `Dup | `Uni ]

A handle for a map from keys of type 'key to values of type 'value. The map may support only a single value per key ([ `Dup ]) or multiple values per key ([ `Dup | `Uni ]).

type 'a card =
| Nodup : [ `Uni ] card
| Dup : [ `Dup | `Uni ] card
val create : [< `Dup | `Uni ] as 'dup card -> key:'key Conv.t -> value:'value Conv.t -> ?⁠txn:[> `Read | `Write ] Txn.t -> ?⁠name:string -> Env.t -> ('key'value'dup) t

create dup ~key ~value env open (and possibly create) a map in the environment env.

dup may be Dup or Nodup, specifying whether the map supports multiple values per key.

Only a single transaction may call this function at a time. This transaction needs to finish before any other transaction may call this function.

parameter name

if omitted the unnamed map will be opened. Otherwise make sure that Env.create was called with a large enough ~max_maps.

parameter key

Converter for keys

parameter value

Converter for values

raises Invalid_argument

if an existing map doesn't support duplicates, but duplicates where requested.

val open_existing : [< `Dup | `Uni ] as 'dup card -> key:'key Conv.t -> value:'value Conv.t -> ?⁠txn:[> `Read ] Txn.t -> ?⁠name:string -> Env.t -> ('key'value'dup) t

open_existing env is like create, but only opens already existing maps.

raises Not_found

if the map doesn't exist.

val env : (___) t -> Env.t

env map returns the environment of map.

val get : ('key'value_) t -> ?⁠txn:[> `Read ] Txn.t -> 'key -> 'value

get map key returns the first value associated to key.

raises Not_found

if the key is not in the map.

module Flags = Lmdb__.Lmdb_bindings.PutFlags
val add : ('key'value_) t -> ?⁠txn:[> `Write ] Txn.t -> ?⁠flags:Flags.t -> 'key -> 'value -> unit

add map key value adds value to key.

For a map not supporting duplicates an existing value is overwritten. For a map supporting duplicates the value is added to the key. This is the same as overwrite for duplicate maps, but overwrite ~flags:Flags.no_overwrite for non-duplicate maps.

parameter flags

Flags

raises Exists

on maps not supporting duplicates if the key already exists.

raises Exists

if key is already bound to value and Map.Flags.no_dup_data was passed.

val set : ('key'value_) t -> ?⁠txn:[> `Write ] Txn.t -> ?⁠flags:Flags.t -> 'key -> 'value -> unit

set map key value sets binding of key to value.

Values of an already existing key are silently overwritten.

parameter flags

Flags

val remove : ('key'value_) t -> ?⁠txn:[> `Write ] Txn.t -> ?⁠value:'value -> 'key -> unit

remove map key removes key from map.

parameter value

Only the specified value is removed. If not provided, all the values of key and key itself are removed.

raises Not_found

if the key is not in the map.

Misc

val stat : ?⁠txn:[> `Read ] Txn.t -> ('key'value_) t -> Mdb.stat
val drop : ?⁠txn:[> `Write ] Txn.t -> ?⁠delete:bool -> ('key'value_) t -> unit

drop ?delete map Empties map.

parameter delete

If true map is also deleted from the environment and the handle map invalidated.

val compare_key : ('key'value_) t -> ?⁠txn:[> `Read ] Txn.t -> 'key -> 'key -> int

compare_key map ?txn a b Compares a and b as if they were keys in map.

val compare : ('key'value_) t -> ?⁠txn:[> `Read ] Txn.t -> 'key -> 'key -> int

compare map ?txn a b Same as compare_key.

val compare_val : ('key'value[> `Dup ]) t -> ?⁠txn:[> `Read ] Txn.t -> 'value -> 'value -> int

compare_val map ?txn a b Compares a and b as if they were values in a dup_sort map.