Exleveldb v0.10.0 Exleveldb

Exleveldb is a thin wrapper around Basho’s eleveldb. At the moment, Exleveldb exposes the functions defined in this module.

Summary

Functions

Takes a reference as returned by open/2 and closes the specified datastore if open

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

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

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

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

Takes a reference as returned by open/2, a key, and an options list and retrieves a value in LevelDB by key

Takes a reference as returned by open/2 and checks whether the datastore specified by db_ref is empty

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

Takes an iterator reference, closes the iterator, and returns :ok

Takes an iterator reference and an action and returns the corresponding key-value pair

Takes a reference as returned by open/2 and an anonymous function, and maps over the key-value pairs in the datastore

Takes a reference as returned by open/2 and an anonymous function, and maps over the keys in the datastore

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}]

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

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

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

Performs a batch write to the datastore, either deleting or putting key-value pairs

Types

db_acc()
db_acc :: any
db_key()
db_key :: Atom | Bitstring
db_location()
db_location :: binary
db_reference()
db_reference :: binary
itr_reference()
itr_reference :: binary
open_options()
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: charlist, tiered_slow_prefix: charlist]
read_options()
read_options :: [verify_checksums: boolean, fill_cache: boolean, iterator_refresh: boolean]
write_actions()
write_actions :: [{:put, db_key, Bitstring} | {:delete, db_key} | :clear]
write_options()
write_options :: [{:sync, boolean}]

Functions

close(db_ref)
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.

delete(db_ref, key, opts \\ [])
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.

destroy(path, opts \\ [])
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.

fold(db_ref, fun, acc, opts \\ [])
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.

fold_keys(db_ref, fun, acc, opts \\ [])
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.

get(db_ref, key, opts \\ [])
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.

is_empty?(db_ref)
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.

iterator(db_ref, opts \\ [])
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.

iterator(db_ref, opts, atom)
iterator(db_reference, read_options, :keys_only) ::
  {:ok, itr_reference} |
  {:error, any}
iterator_close(iter_ref)
iterator_close(itr_reference) :: :ok

Takes an iterator reference, closes the iterator, and returns :ok.

iterator_move(iter_ref, action)
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.

map(db_ref, fun)
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.

map_keys(db_ref, fun)
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.

open(name, opts \\ [create_if_missing: true])
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'}}.

put(db_ref, key, val, opts \\ [])

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.

repair(path, opts \\ [])
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.

stream(db_ref)

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.

stream(db_ref, atom)
write(db_ref, updates, opts \\ [])
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.