Exleveldb v0.14.0 Exleveldb View Source

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

Link to this section 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

Link to this section Types

Link to this type db_key() View Source
db_key() :: Atom | Bitstring
Link to this type db_location() View Source
db_location() :: binary()
Link to this type db_reference() View Source
db_reference() :: binary()
Link to this type itr_reference() View Source
itr_reference() :: binary()
Link to this type open_options() View Source
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()
]
Link to this type read_options() View Source
read_options() :: [
  verify_checksums: boolean(),
  fill_cache: boolean(),
  iterator_refresh: boolean()
]
Link to this type write_actions() View Source
write_actions() :: [{:put, db_key(), Bitstring} | {:delete, db_key()} | :clear]
Link to this type write_options() View Source
write_options() :: [{:sync, boolean()}]

Link to this section Functions

Link to this function close(db_ref) View Source
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.

Link to this function delete(db_ref, key, opts \\ []) View Source
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.

Link to this function destroy(path, opts \\ []) View Source
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.

Link to this function fold(db_ref, fun, acc, opts \\ []) View Source
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.

Link to this function fold_keys(db_ref, fun, acc, opts \\ []) View Source
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.

Link to this function get(db_ref, key, opts \\ []) View Source
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.

Link to this function is_empty?(db_ref) View Source
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.

Link to this function iterator(db_ref, opts \\ []) View Source
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.

Link to this function iterator(db_ref, opts, atom) View Source
iterator(db_reference(), read_options(), :keys_only) ::
  {:ok, itr_reference()} | {:error, any()}
Link to this function iterator_close(iter_ref) View Source
iterator_close(itr_reference()) :: :ok

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

Link to this function iterator_move(iter_ref, action) View Source
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.

Link to this function map(db_ref, fun) View Source
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.

Link to this function map_keys(db_ref, fun) View Source
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.

Link to this function open(name, opts \\ [create_if_missing: true]) View Source
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'}}.

Link to this function put(db_ref, key, val, opts \\ []) View Source

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.

Link to this function repair(path, opts \\ []) View Source
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.

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.

Link to this function write(db_ref, updates, opts \\ []) View Source
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.