Exleveldb
Exleveldb is a thin wrapper around Basho’s eleveldb. At the moment, Exleveldb exposes the functions defined in this module.
Summary↑
close(db_ref) | Takes a reference as returned by |
delete(db_ref, key, opts \\ []) | Takes a reference as returned by |
destroy(path, opts \\ []) | Destroy a database, which implies the deletion of the database folder. Takes a string with the path to the database and a list of options.
Returns |
fold(db_ref, fun, acc, opts \\ []) | Takes a reference as returned by |
fold_keys(db_ref, fun, acc, opts \\ []) | Takes a reference as returned by |
get(db_ref, key, opts \\ []) | Takes a reference as returned by |
is_empty?(db_ref) | Takes a reference as returned by |
iterator(db_ref, opts \\ []) | Takes a reference to a data store, then creates and returns |
iterator(db_ref, opts, atom3) | |
iterator_close(iter_ref) | Takes an iterator reference, closes the iterator, and returns |
iterator_move(iter_ref, action) | Takes an iterator reference and an action and returns the corresponding key-value pair |
map(db_ref, fun) | Takes a reference as returned by |
map_keys(db_ref, fun) | Takes a reference as returned by |
open(name, opts \\ [create_if_missing: true]) | Takes a |
put(db_ref, key, val, opts \\ []) | Takes a reference as returned by |
repair(path, opts \\ []) | Takes the path to the leveldb database and a list of options. The standard recomended option is the empty list |
stream(db_ref) | Takes a reference as returned by |
stream(db_ref, atom2) | |
write(db_ref, updates, opts \\ []) | Performs a batch write to the datastore, either deleting or putting key-value pairs |
Types ↑
db_location :: binary
db_reference :: binary
itr_reference :: binary
db_key :: Atom | Bitstring
db_acc :: any
open_options :: [create_if_missing: boolean, error_if_exists: boolean, write_buffer_size: pos_integer, block_size: pos_integer, sst_block_size: pos_integer, block_restart_interval: pos_integer, block_size_steps: pos_integer, paranoid_checks: boolean, verify_compactions: boolean, compression: boolean, use_bloomfilter: boolean | pos_integer, total_memory: pos_integer, total_leveldb_mem: pos_integer, total_leveldb_mem_percent: pos_integer, is_internal_db: boolean, limited_developer_mem: boolean, eleveldb_threads: pos_integer, fadvise_willneed: boolean, block_cache_threshold: pos_integer, delete_threshold: pos_integer, tiered_slow_level: pos_integer, tiered_fast_prefix: char_list, tiered_slow_prefix: char_list]
read_options :: [verify_checksums: boolean, fill_cache: boolean, iterator_refresh: boolean]
write_options :: [{:sync, boolean}]
write_actions :: [{:put, db_key, Bitstring} | {:delete, db_key} | :clear]
Functions
Specs:
- close(db_reference) :: :ok | {:error, any}
Takes a reference as returned by open/2
and closes the specified datastore if open.
Returns :ok
or {:error, {:type, 'reason for error'}}
on error.
Specs:
- delete(db_reference, db_key, write_options) :: :ok | {:error, any}
Takes a reference as returned by open/2
, a key and an options list and
deletes the value associated with key
in the datastore, db_ref
.
Returns :ok
when successful or {:error, reference, {:type, action}}
on error.
Specs:
- destroy(db_location, open_options) :: :ok | {:error, any}
Destroy a database, which implies the deletion of the database folder. Takes a string with the path to the database and a list of options.
Returns :ok
on success and {:error, reason}
on error.
Specs:
- fold(db_reference, Fun, db_acc, read_options) :: any
Takes a reference as returned by open/2
, an anonymous function,
an accumulator, and an options list and folds over the key-value pairs
in the datastore specified in db_ref
.
Returns the result of the last call to the anonymous function used in the fold.
The two arguments passed to the anonymous function, fun
are a tuple of the
key value pair and acc
.
Specs:
- fold_keys(db_reference, Fun, db_acc, read_options) :: any
Takes a reference as returned by open/2
, an anonymous function,
an accumulator, and an options list and folds over the keys
of the open datastore specified by db_ref
.
Returns the result of the last call to the anonymous function used in the fold.
The two arguments passed to the anonymous function, fun
are a key and acc
.
Specs:
- get(db_reference, db_key, read_options) :: {:ok, Bitstring} | :not_found
Takes a reference as returned by open/2
, a key, and an options list and
retrieves a value in LevelDB by key.
Returns {:ok, value}
when successful or :not_found
on failed lookup.
Specs:
- is_empty?(db_reference) :: true | false
Takes a reference as returned by open/2
and checks whether the datastore
specified by db_ref
is empty.
Returns true
if empty and false
if not.
Specs:
- iterator(db_reference, read_options) :: {:ok, itr_reference} | {:error, any}
Takes a reference to a data store, then creates and returns {:ok, ""}
where the
seemingly empty binary is a reference to the iterator. As with db_ref
, the iterator
reference is an opaque type and as such appears to be an empty binary because it’s
internal to the eleveldb module.
If the :keys_only
atom is given after opts, the iterator will only traverse keys.
Specs:
- iterator(db_reference, read_options, :keys_only) :: {:ok, itr_reference} | {:error, any}
Specs:
- iterator_close(itr_reference) :: :ok
Takes an iterator reference, closes the iterator, and returns :ok
.
Specs:
- iterator_move(itr_reference, Atom) :: {:ok, Atom, Atom} | {:error, Atom}
Takes an iterator reference and an action and returns the corresponding key-value pair.
An action can either be :first
, :last
, :next
, :prev
, :prefetch
, or a binary
representing the key of the pair you want to fetch.
Specs:
- map(db_reference, Fun) :: List
Takes a reference as returned by open/2
and an anonymous function,
and maps over the key-value pairs in the datastore.
Returns the results of applying the anonymous function to every key-value pair currently in the datastore.
The argument to the anonymous function is i
for the current item,
i.e. key-value pair, in the list.
Specs:
- map_keys(db_reference, Fun) :: List
Takes a reference as returned by open/2
and an anonymous function,
and maps over the keys in the datastore.
Returns the results of applying the anonymous function to every key in currently in the datastore.
The argument to the anonymous function is i
for the current item,
i..e key, in the list.
Specs:
- open(db_location, open_options) :: {:ok, db_reference} | {:error, any}
Takes a name
string and an opts
list and opens a new datastore in the
directory called name
. If name
does not exist already and no opts
list
was provided, opts
will default to [{:create_if_missing, :true}]
.
Returns {:ok, ""}
where what appears to be an empty binary is a reference to the opened
datastore or, on error, {:error, {:type, 'reason for error'}}
.
Takes a reference as returned by open/2
, a key and an options list and
puts a single key-value pair into the datastore specified by the reference, db_ref
.
Returns :ok
if successful or {:error, reference, {:type, action}}
on error.
Specs:
- repair(db_location, open_options) :: :ok | {:error, any}
Takes the path to the leveldb database and a list of options. The standard recomended option is the empty list []
.
Before calling repair/2
, close the connection to the database with close/1
.
Returns :ok
on success and {:error, reason}
on error.
Specs:
- stream(db_reference) :: Enumerable.t
Takes a reference as returned by open/2
,
and constructs a stream of all key-value pairs in the referenced datastore.
When called with :keys_only
as its second argument, only keys,
not values will be emitted by the stream.
Returns a stream with the datastore’s key-value pairs as its enumerable.
When calling Enum.take/2
or similar on the resulting stream,
specifying more entries than are in the referenced datastore
will not yield an error but simply return a list of all pairs in the datastore.
Specs:
- write(db_reference, write_actions, write_options) :: :ok | {:error, any}
Performs a batch write to the datastore, either deleting or putting key-value pairs.
Takes a reference to an open datastore, a list of tuples (containing atoms for operations and strings for keys and values) designating operations (delete or put) to be done, and a list of options.
Returns :ok
on success and {:error, reference, {:type, reason}}
on error.