Ets
:ets, the Elixir way
Ets is an Elixir wrapper for 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:
- Conforming to Elixir standards:
- Data (on insert) and keys (on lookup) move to first parameter to support pipelines.
- Two versions of all functions:
- Main function (e.g.
lookupreturns{:ok, return}/{:error, reason}tuples. - Bang function (e.g.
lookup!) returns value or raises on :error.
- Main function (e.g.
- Inserted data is returned from insert calls to support pipelines.
- All options specified via keyword list.
- Wrapping unhelpful
ArgumentError's with appropriate error returns. - Wrapping
$end_of_tablein appropriate error returns/raises. - Preventing insertion of
$end_of_tablewhere possible without affecting performance. - Providing Elixir friendly documentation
- Providing two levels of abstraction, one addressing the most common cases (
Ets), and the other addressing the advanced tuple record based cases (Ets.Record)Ets- designed for most common case of inserting a single key/value pair in a
set/ordered_set(withinsert!).bag/duplicate_bag(which allow repeat keys) are also supported (withinsert_multi) - designed for most common case of looking up a single value for a key in a
set/ordered_set(withlookup!).bag/duplicate_bag(which allow repeat keys) are also supported (withlookup_multi) insert/insert_new- takes a key and single valuelookuptakes a key, returns a single value ornil(error if more than one found)insert_multi/insert_multi_new- takes list of key/value pairs, or a list of values and a key, retainsatomic and isolatednature of:etsmultiple inserts.lookup_multitakes a key, returns list of values found for key
- designed for most common case of inserting a single key/value pair in a
Ets.Recordadvanced module for granting direct wrappers to:etsTuple Record based functions.insert/insert_new- takes a record tuplelookup!- takes a key, returns record tuple ornil(raises if more than one found)insert_multi/insert_multi_new- takes a list of record tuples, retainsatomic and isolatednature of:etsmultiple inserts.lookup_multitakes a key, returns list of record tuples- Advanced features such as
matchandselect
TODO:
Ets- Insert
- Lookup
- Delete
- Delete All
- First
- Next
- Last
- Previous
- Has Key (Member)
Ets.Table- Info
- All
- Delete
- TableToList
- Whereis
- Rename
Ets.Table.New
Ets.Record- Insert
- Lookup
- Match
Installation
If available in Hex, the package can be installed
by adding ets to your list of dependencies in mix.exs:
def deps do
[
{:ets, "~> 0.1.0"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/ets.
Contributing
Contributions welcome. Specifically looking to:
- Add remainder of functions (See Erlang Docs).
- Discover and add zero-impact recovery for any additional possible
:etsArgumentErrors.