ets v0.1.0 Ets.Table

Module for performing table level operations on :ets tables.

Link to this section Summary

Functions

Same as delete/1 but raises on :error

Returns :ok/:error tuple. :ok tuple contains list of table identifiers (atoms or references)

Same as delete/1 but raises on :error

Deletes a table

Same as info/1 but raises on :error

Looks up info on table

Same as rename/2 but raises on :error

Renames the specified table to the specified name

Same as to_list/2 but raises on :error

Returns contents of table as a list of tuples

Same as whereis/1 but raises on :error

Locates table with the specified name

Link to this section Functions

Same as delete/1 but raises on :error.

Link to this function all()
all() :: {:ok, [Ets.table_identifier()]} | {:error, any()}

Returns :ok/:error tuple. :ok tuple contains list of table identifiers (atoms or references).

Examples

iex> {:ok, all} = Ets.Table.all()
iex> Enum.member?(all, :my_ets_table)
false

iex> Ets.Table.New.set(:my_ets_table)
iex> {:ok, all} = Ets.Table.all()
iex> Enum.member?(all, :my_ets_table)
true
Link to this macro catch_table_already_exists(table_name, list) (macro)

Same as delete/1 but raises on :error.

Returns table identifier.

Link to this function delete(table)
delete(Ets.table_identifier()) ::
  {:ok, Ets.table_identifier()} | {:error, :table_not_found}

Deletes a table.

Returns :ok/:error tuple. :ok tuple contains table identifier given.

Examples

iex> Ets.Table.New.set(:my_ets_table)
iex> Enum.member?(Ets.Table.all!(), :my_ets_table)
true
iex> Ets.Table.delete!(:my_ets_table)
:my_ets_table
iex> Enum.member?(Ets.Table.all!(), :my_ets_table)
false

Same as info/1 but raises on :error

Returns keyword list of info on table.

Link to this function info(table)
info(Ets.table_identifier()) :: {:ok, keyword()} | {:error, :table_not_found}

Looks up info on table.

Returns :ok/:error tuple. :ok tuple contains keyword list of info on table.

Examples

iex> Ets.Table.New.set(:my_ets_table)
iex> {:ok, info} = Ets.Table.info(:my_ets_table)
iex> info[:type]
:set
iex> info[:named_table]
true
iex> info[:protection]
:protected

Same as rename/2 but raises on :error.

Returns the specified new name of the table

Link to this function rename(new_name, table)
rename(Ets.table_name(), Ets.table_identifier()) ::
  {:ok, Ets.table_name()} | {:error, :table_not_found}

Renames the specified table to the specified name.

Returns :ok/:error tuple. :ok tuple contains the specified new name of the table.

Examples

iex> Ets.Table.New.set(:my_ets_table)
iex> ref = Ets.Table.info!(:my_ets_table)[:id]
iex> Ets.Table.rename(:new_name, :my_ets_table)
iex> ref == Ets.Table.info!(:new_name)[:id]
true
Link to this function to_list!(table)
to_list!(Ets.table_identifier()) :: [tuple()]

Same as to_list/2 but raises on :error.

Returns table contents as a list.

Link to this function to_list(table)
to_list(Ets.table_identifier()) :: {:ok, [tuple()]} | {:error, :table_not_found}

Returns contents of table as a list of tuples.

Returns :ok/:error tuple. :ok tuple contains table contents as a list.

Examples

iex> Ets.Table.New.bag(:my_ets_table)
iex> Ets.insert_multi([:a, :b, :c], :my_ets_table, :key1)
iex> Ets.insert_multi([:a, :b, :c], :my_ets_table, :key2)
iex> Ets.Table.to_list(:my_ets_table)
{:ok, [{:key2, :a}, {:key2, :b}, {:key2, :c}, {:key1, :a}, {:key1, :b}, {:key1, :c}]}
Link to this function whereis!(table)
whereis!(atom()) :: Ets.ets_table_reference()

Same as whereis/1 but raises on :error.

Returns table reference

Link to this function whereis(table_name)
whereis(atom()) :: {:ok, Ets.ets_table_reference()} | {:error, :table_not_found}

Locates table with the specified name.

Returns :ok/:error tuple. :ok tuple contains table reference.

Examples

iex> Ets.Table.New.set(:my_ets_table)
iex> {:ok, ref} = Ets.Table.whereis(:my_ets_table)
iex> is_reference(ref)
true