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 ]
).
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 environmentenv
.dup
may beDup
orNodup
, 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 likecreate
, but only opens already existing maps.- raises Not_found
if the map doesn't exist.
val get : ('key, 'value, _) t -> ?txn:[> `Read ] Txn.t -> 'key -> 'value
get map key
returns the first value associated tokey
.- 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
addsvalue
tokey
.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, butoverwrite ~flags:Flags.no_overwrite
for non-duplicate maps.- parameter flags
- raises Exists
on maps not supporting duplicates if the key already exists.
- raises Exists
if key is already bound to
value
andMap.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 ofkey
tovalue
.Values of an already existing key are silently overwritten.
- parameter flags
val remove : ('key, 'value, _) t -> ?txn:[> `Write ] Txn.t -> ?value:'value -> 'key -> unit
remove map key
removeskey
frommap
.- parameter value
Only the specified value is removed. If not provided, all the values of
key
andkey
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
Emptiesmap
.- parameter delete
If
true
map
is also deleted from the environment and the handlemap
invalidated.
val compare_key : ('key, 'value, _) t -> ?txn:[> `Read ] Txn.t -> 'key -> 'key -> int
compare_key map ?txn a b
Comparesa
andb
as if they were keys inmap
.