Page
Library
Module
Module type
Parameter
Class
Class type
Source
LevelDB
SourceAccess to leveldb
databases.
* * A database may only be opened by one process at a time; this is enforced * by LevelDB by using a file lock. Within a process, operations on a value * of type db
(such as get
, put
, iterator
, Iterator.make
or * Snapshot.make
) can be performed concurrently in different threads. * Values of type iterator
, writebatch
, snapshot
and read_access
must * not be used simultaneously from two different threads, so external * synchronization (e.g. using Mutex
) is required. * * As an exception to the above rule, it is possible to close a db
with * iterator
, snapshot
or read_access
values in use. Values of these * types can also be released/closed in a thread while they are being used in * another. In both cases, the thread that is releasing/closing the value * will wait until the current operation is finished and invalidate the value * so that any further operations on it will fail.
Errors (apart from Not_found
) are notified with Error s
exceptions.
Database
Database iterators.
Batch write operations.
Immutable database snapshots.
Read-only access to the DB or a snapshot.
Type that represents a const Comparator*
pointer (refer to * LevelDB's comparator.h
). If you want to define your own, * use an external function of type unit -> comparator
* returning the pointer.
Type that represents a const Env*
pointer (refer to * LevelDB's options.h
). If you want to define your own, * use an external function of type unit -> env
* returning the pointer.
Destroy the contents of the database in the given directory. *
If a DB cannot be opened, you may attempt to call this method to resurrect * as much of the contents of the database as possible. Some data may be * lost, so be careful when calling this function on a database that contains * important information. *
val open_db :
?write_buffer_size:int ->
?max_open_files:int ->
?block_size:int ->
?block_restart_interval:int ->
?comparator:comparator ->
?cache_size:int ->
?env:env ->
string ->
db
Open a leveldb database in the given directory. *
Close the database. All further operations on it will fail. * Existing snapshots, read_access values and iterators are released and * invalidated. If such values are being used in a concurrent thread, * the current thread will wait until the operation is finished and then * proceed to invalidate the value, making any further uses on it fail, and * release it. * Note that the database is closed automatically in the finalizer if you * don't close it manually.
Read-only access to the DB.
Return a new iterator. Refer to Iterator.make
.
get_approximate_size from_key to_key
returns the approximate size * on disk of the range comprised between from_key
and to_key
.
Compact specified range. None
is treated as a key before (resp. after) * all keys in the database; therefore compact_range db None None
will * compact the whole DB.
Note that in the following functions the contents of the key will be * copied to the stack, so exceedingly large keys could cause a stack * overflow.
put ?sync key value
adds (or replaces) a binding to the database. *
delete ?sync key
deletes the binding for the given key. *
iter f db
applies f
to all the bindings in db
until it returns * false
, i.e. runs f key value
for all the bindings in lexicographic * key order.
Like iter
, but proceed in reverse lexicographic order.
iter_from f db start
applies f key value
for all the bindings after * start
(inclusive) until it returns false.
iter_from f db start
applies f key value
for all the bindings before * start
(inclusive) in reverse lexicographic order until f
returns * false
..
Access to database snapshots. * Note that the functions that accept a key will copy its contents to the * stack, so exceedingly large keys could cause a stack overflow.
Read-only access to databases and snapshots. * Note that the functions that accept a key will copy its contents to the * stack, so exceedingly large keys could cause a stack overflow.