DBKV (dbkv v0.2.5) View Source

A disk-based key-value store built on top of :dets. Inspired by CubDB's intuitive API.

Link to this section Summary

Functions

Returns all entries from table.

Applies fun to each entry stored in table in some unspecified order.

Closes a table. Only processes that have opened a table are allowed to close it. All open tables must be closed before the system is stopped.

Decrements a number field by one.

Deletes the entry in table for a specific key.

Deletes all entries from table.

Deletes entries from table where the key is with the specified range. By default, the range is inclusive. The range boundaries can be excluded by setting :min_inclusive or :max_inclusive to false.

Deletes each entry from table such that applying match_spec to the entry returns true. Returns the number of deleted entries.

Delete all entries from table where the key is less than or equal to max_key. The boundary can be excluded by setting inclusive to false.

Delete all entries from table where the value is less than or equal to max_value. The boundary can be excluded by setting inclusive to false.

Delete all entries from table where the key is greater than or equal to min_key. The boundary can be excluded by setting inclusive to false.

Delete all entries from table where the value is greater than or equal to min_value. The boundary can be excluded by setting inclusive to false.

Delete all entries from table where the value is equal to value.

Deletes entries from table where the valye is with the specified range. By default, the range is inclusive. The range boundaries can be excluded by setting :min_inclusive or :max_inclusive to false.

Returns the name of the file where table is stored.

Gets the value for a specific key in table.

Returns whether the given key exists in table.

Increments a number field by one.

info(table) deprecated

Returns information about table.

Replaces the existing entries of table with entries.

Returns all keys from table.

Opens a table. An empty :dets table is created if no file exists.

Returns whether table is open.

Puts the given value under key in table.

Puts the given value under key unless the entry key already exists in table.

Calls Function on successive elements of table together with an extra argument acc. The table elements are traversed in unspecified order. reducer must return a new accumulator that is passed to the next call. acc is returned if the table is empty.

Returns a specified range of entries from table. By default, the range is inclusive. The range boundaries can be excluded by setting :min_inclusive or :max_inclusive to false.

Returns the results of applying match_spec to all or n entries stored in table.

Returns all entries from table where the key is less than or equal to max_key. The boundary can be excluded by setting inclusive to false.

Returns all entries from table where the value is less than or equal to max_value. The boundary can be excluded by setting inclusive to false.

Returns all entries from table where the key is greater than or equal to min_key. The boundary can be excluded by setting inclusive to false.

Returns all entries from table where the value is greater than or equal to min_value. The boundary can be excluded by setting inclusive to false.

Returns all entries from table where the value is equal to value.

Returns a specified range of entries from table. By default, the range is inclusive. The range boundaries can be excluded by setting :min_inclusive or :max_inclusive to false.

Returns the size of the collection in table.

Updates the key in table with the given function.

Returns all values from table.

Link to this section Types

Specs

dbkv_options() :: [name: t(), data_dir: binary()]

Specs

entry() :: {any(), any()}

Specs

match_spec() :: [
  {{:"$1", :"$2"}, [{any(), any(), any()}, ...], [:"$_", ...]},
  ...
]

Match Specifications. See https://erlang.org/doc/man/dets.html#type-match_spec

Specs

range_options() :: [min_inclusive: boolean(), max_inclusive: boolean()]

Specs

t() :: atom()

Link to this section Functions

Specs

all(t()) :: [entry()] | {:error, any()}

Returns all entries from table.

Specs

all(t(), (key :: any(), value :: any() -> any())) :: [any()] | {:error, any()}

Applies fun to each entry stored in table in some unspecified order.

Specs

close(t()) :: :ok | {:error, any()}

Closes a table. Only processes that have opened a table are allowed to close it. All open tables must be closed before the system is stopped.

Link to this function

decrement(table, key, by)

View Source

Specs

decrement(t(), any(), number()) :: number()

Decrements a number field by one.

Specs

delete(t(), any()) :: :ok | {:error, any()}

Deletes the entry in table for a specific key.

Specs

delete_all(t()) :: :ok | {:error, any()}

Deletes all entries from table.

Link to this function

delete_by_key_range(table, min_key, max_key, opts \\ [])

View Source

Specs

delete_by_key_range(t(), any(), any(), range_options()) ::
  integer() | {:error, any()}

Deletes entries from table where the key is with the specified range. By default, the range is inclusive. The range boundaries can be excluded by setting :min_inclusive or :max_inclusive to false.

Link to this function

delete_by_match_spec(table, match_spec)

View Source

Specs

delete_by_match_spec(t(), match_spec()) :: integer() | {:error, any()}

Deletes each entry from table such that applying match_spec to the entry returns true. Returns the number of deleted entries.

Link to this function

delete_by_max_key(table, max_key, inclusive \\ true)

View Source

Specs

delete_by_max_key(t(), any(), boolean()) :: integer() | {:error, any()}

Delete all entries from table where the key is less than or equal to max_key. The boundary can be excluded by setting inclusive to false.

Link to this function

delete_by_max_value(table, max_value, inclusive \\ true)

View Source

Specs

delete_by_max_value(t(), any(), boolean()) :: integer() | {:error, any()}

Delete all entries from table where the value is less than or equal to max_value. The boundary can be excluded by setting inclusive to false.

Link to this function

delete_by_min_key(table, min_key, inclusive \\ true)

View Source

Specs

delete_by_min_key(t(), any(), boolean()) :: integer() | {:error, any()}

Delete all entries from table where the key is greater than or equal to min_key. The boundary can be excluded by setting inclusive to false.

Link to this function

delete_by_min_value(table, min_value, inclusive \\ true)

View Source

Specs

delete_by_min_value(t(), any(), boolean()) :: integer() | {:error, any()}

Delete all entries from table where the value is greater than or equal to min_value. The boundary can be excluded by setting inclusive to false.

Link to this function

delete_by_value(table, value)

View Source

Specs

delete_by_value(t(), any()) :: integer() | {:error, any()}

Delete all entries from table where the value is equal to value.

Link to this function

delete_by_value_range(table, min_value, max_value, opts \\ [])

View Source

Specs

delete_by_value_range(t(), any(), any(), range_options()) ::
  integer() | {:error, any()}

Deletes entries from table where the valye is with the specified range. By default, the range is inclusive. The range boundaries can be excluded by setting :min_inclusive or :max_inclusive to false.

Specs

filename(t()) :: charlist() | :undefined

Returns the name of the file where table is stored.

Link to this function

get(table, key, default \\ nil)

View Source

Specs

get(t(), any(), any()) :: any()

Gets the value for a specific key in table.

Specs

has_key?(t(), any()) :: boolean()

Returns whether the given key exists in table.

Link to this function

increment(table, key, by)

View Source

Specs

increment(t(), any(), number()) :: number()

Increments a number field by one.

This function is deprecated. Use :dets.info/1 instead.

Specs

info(t()) :: map() | :undefined

Returns information about table.

Link to this function

init_table(table, entries)

View Source

Specs

init_table(t(), [entry()]) :: :ok | {:error, any()}

Replaces the existing entries of table with entries.

Specs

keys(t()) :: [any()] | {:error, any()}

Returns all keys from table.

Specs

open(dbkv_options()) :: {:ok, t()} | {:error, any()}

Opens a table. An empty :dets table is created if no file exists.

The optional argument is a keyword list of options:

  • name: a name of the table (defaults to DBKV)
  • data_dir: the directory path where the database files will be stored (defaults to "tmp")

Specs

open?(t()) :: boolean()

Returns whether table is open.

Specs

put(t(), any(), any()) :: :ok | {:error, any()}

Puts the given value under key in table.

Link to this function

put_new(table, key, value)

View Source

Specs

put_new(t(), any(), any()) :: :ok | {:error, any()}

Puts the given value under key unless the entry key already exists in table.

Link to this function

reduce(table, acc, reducer)

View Source

Specs

reduce(t(), any(), (entry(), any() -> any())) :: any()

Calls Function on successive elements of table together with an extra argument acc. The table elements are traversed in unspecified order. reducer must return a new accumulator that is passed to the next call. acc is returned if the table is empty.

Link to this function

select_by_key_range(table, min_key, max_key, opts \\ [])

View Source

Specs

select_by_key_range(t(), any(), any(), range_options()) ::
  [entry()] | {:error, any()}

Returns a specified range of entries from table. By default, the range is inclusive. The range boundaries can be excluded by setting :min_inclusive or :max_inclusive to false.

Link to this function

select_by_match_spec(table, match_spec, n \\ :default)

View Source

Specs

select_by_match_spec(t(), match_spec(), non_neg_integer()) ::
  [any()] | {:error, any()}

Returns the results of applying match_spec to all or n entries stored in table.

Link to this function

select_by_max_key(table, max_key, inclusive \\ true)

View Source

Specs

select_by_max_key(t(), any(), boolean()) :: [entry()] | {:error, any()}

Returns all entries from table where the key is less than or equal to max_key. The boundary can be excluded by setting inclusive to false.

Link to this function

select_by_max_value(table, max_value, inclusive \\ true)

View Source

Specs

select_by_max_value(t(), any(), boolean()) :: [entry()] | {:error, any()}

Returns all entries from table where the value is less than or equal to max_value. The boundary can be excluded by setting inclusive to false.

Link to this function

select_by_min_key(table, min_key, inclusive \\ true)

View Source

Specs

select_by_min_key(t(), any(), boolean()) :: [entry()] | {:error, any()}

Returns all entries from table where the key is greater than or equal to min_key. The boundary can be excluded by setting inclusive to false.

Link to this function

select_by_min_value(table, min_value, inclusive \\ true)

View Source

Specs

select_by_min_value(t(), any(), boolean()) :: [entry()] | {:error, any()}

Returns all entries from table where the value is greater than or equal to min_value. The boundary can be excluded by setting inclusive to false.

Link to this function

select_by_value(table, value)

View Source

Specs

select_by_value(t(), any()) :: [entry()] | {:error, any()}

Returns all entries from table where the value is equal to value.

Link to this function

select_by_value_range(table, min_value, max_value, opts \\ [])

View Source

Specs

select_by_value_range(t(), any(), any(), range_options()) ::
  [any()] | {:error, any()}

Returns a specified range of entries from table. By default, the range is inclusive. The range boundaries can be excluded by setting :min_inclusive or :max_inclusive to false.

Specs

size(t()) :: integer() | :undefined

Returns the size of the collection in table.

Link to this function

update(table, key, default, fun)

View Source

Specs

update(t(), any(), any(), (value :: any() -> any())) :: :ok | {:error, any()}

Updates the key in table with the given function.

If key is present in table then the existing value is passed to fun and its result is used as the updated value of key. If key is not present in table, default is inserted as the value of key. The default value will not be passed through the update function.

Specs

values(t()) :: [any()] | {:error, any()}

Returns all values from table.