Ets

:ets, the Elixir way

Build Status Coverage Status Project license Hex.pm package Hex.pm downloads

Ets is a set of Elixir modules that wrap Erlang Term Storage (:ets). The purposes of this package is to improve the developer experience when both learning and interacting with Erlang Term Storage.

This will be accomplished by:

Usage

Creating Ets Tables

Ets Tables can be created using the new function of the appropriate module, either Ets.Set (for ordered and unordered sets) or Ets.Bag (for duplicate or non-duplicate bags) (Ets.Bag coming soon). See module documentation for more examples and documentation.

Create Examples

iex> {:ok, set} = Set.new(ordered: true, keypos: 3, read_concurrency: true, compressed: false)
iex> Set.info!(set)[:read_concurrency]
true
# Named :ets tables via the name keyword
iex> {:ok, set} = Set.new(name: :my_ets_table)
iex> Set.info!(set)[:name]
:my_ets_table

Adding/Updating/Retrieving records

To add records to an Ets table, use put and its variations put_new, put_multi, and put_multi_new. put and put_multi will overwrite existing records with the same key. The _new variations will return an error and not insert if the key already exists. The _multi variations will insert all records in an atomic and isolated manner (or insert no records if at least one is found with put_multi_new)

Record Examples

iex> Set.new(ordered: true)
iex> |> Set.put!({:a, :b})
iex> |> Set.put!({:a, :c})
iex> |> Set.put!({:c, :d})
iex> |> Set.to_list!()
[{:a, :c}, {:c, :d}]
iex> Set.new(ordered: true)
iex> |> Set.put!({:a, :b})
iex> |> Set.put({:a, :c})
{:error, :key_already_exists}

Current Progress

Installation

Ets can be installed by adding ets to your list of dependencies in mix.exs:

def deps do
[
{:ets, "~> 0.2.1"}
]
end

Docs can be found at https://hexdocs.pm/ets.

Contributing

Contributions welcome. Specifically looking to: