EtsHelper
is a wrapper of ETS. It does not try to wrap all the
functionality, only those functions that are constantly used in Elixir projects. It also includes some
new functions. This is a library that could be improved in the future if it is required by new needs.
Add ets_helper
to your list of dependencies in mix.exs
:
def deps do
[{:ets_helper, "~> 0.1.0"}]
end
- New table
iex> EtsHelper.init_table(:my_table)
- New table with options
iex> EtsHelper.init_table(:my_table, [:named_table, :public, {:read_concurrency, true}, {:write_concurrency, true}])
- Insert data
iex> EtsHelper.insert(:my_table, {"key", "data"})
iex> EtsHelper.insert(:my_table, {:key, :data})
iex> EtsHelper.insert(:my_table, {{:key, 2}, {1, 2, 3}})
- Get data
iex> EtsHelper.get(:my_table, "key")
- Get all data
iex> EtsHelper.all(:my_table)
- Get all keys
iex> EtsHelper.keys(:my_table)
- Delete data
iex> EtsHelper.delete(:my_table, "key")
- Delete all data
iex> EtsHelper.delete_all(:my_table)
- Delete all registers whose data matches with the given function
iex> # Delete odd data
iex> EtsHelper.delete_data_with(:my_table, fn x -> rem(x, 2) != 0 end)
- Get data according to given pattern
iex> EtsHelper.insert(table_name, [{:brunte, :horse, 5}, {:ludde, :dog, 5}, {:rufsen, :dog, 7}])
iex> EtsHelper.match(table_name, {:"_", :dog, :"$1"})
- Table Information
iex> EtsHelper.info(:my_table)
Run the tests.
$> mix test