Exleveldb

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

Source

Summary

close(db_ref)

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

delete(db_ref, key, opts \\ [])

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(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 :ok on success and {:error, any} on error

fold(db_ref, fun, acc, opts \\ [])

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

fold_keys(db_ref, fun, acc, opts \\ [])

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

get(db_ref, key, opts \\ [])

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

is_empty?(db_ref)

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

iterator(db_ref, opts \\ [])

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

iterator(db_ref, opts, atom3)
iterator_close(iter_ref)

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

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 open/2 and an anonymous function, and maps over the key-value pairs in the datastore

map_keys(db_ref, fun)

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

open(name, opts \\ [create_if_missing: true])

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

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

repair(path, opts \\ [])

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 {:type, 'reason for error'} 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

stream_keys(db_ref)

Takes a reference as returned by open/2, and constructs a stream of all the keys in the referenced datastore

write(db_ref, updates, opts \\ [])

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

Functions

close(db_ref)

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.

Source
delete(db_ref, key, opts \\ [])

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.

Source
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 :ok on success and {:error, any} on error.

Source
fold(db_ref, fun, acc, opts \\ [])

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.

Source
fold_keys(db_ref, fun, acc, opts \\ [])

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.

Source
get(db_ref, key, opts \\ [])

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.

Source
is_empty?(db_ref)

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.

Source
iterator(db_ref, opts \\ [])

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.

Source
iterator(db_ref, opts, atom3)
Source
iterator_close(iter_ref)

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

Source
iterator_move(iter_ref, action)

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.

Source
map(db_ref, fun)

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.

Source
map_keys(db_ref, fun)

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.

Source
open(name, opts \\ [create_if_missing: true])

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'}}.

Source
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.

Source
repair(path, opts \\ [])

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 {:type, 'reason for error'} on error.

Source
stream(db_ref)

Takes a reference as returned by open/2, and constructs a stream of all key-value pairs in the referenced datastore.

Returns a Stream struct 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.

Source
stream_keys(db_ref)

Takes a reference as returned by open/2, and constructs a stream of all the keys in the referenced datastore.

Returns a Stream struct with the datastore’s keys as its enum field.

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.

Source
write(db_ref, updates, opts \\ [])

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.

Source