Skip to content
ETS Wrapper to help in your Elixir projects
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
lib
test
.gitignore
.travis.yml
LICENSE
README.md
mix.exs
mix.lock

README.md

EtsHelper

hex.pm hexdocs.pm Build Status

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.

Installation

Add ets_helper to your list of dependencies in mix.exs:

def deps do
  [{:ets_helper, "~> 0.1.0"}]
end

How to use it

  • 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)

Test

Run the tests.

$> mix test 
You can’t perform that action at this time.