EtsSelect - an ETS match spec builder from a simple query language.

I needed to store some structs/maps in ETS and wanted to use a query language that felt simple and approachable.

After looking at several alternatives, I noticed that all the wrappers around ETS match specifications were doing a bit too much for my taste. This is how EtsSelect came to life. :slightly_smiling_face:

You can dump your maps/structs into an ETS table and select them using the following query syntax:

# "OR" query
%{or: [[:=, :field1, "value1"], [:=, :field2, "value2"]]}

# "AND" query
%{and: [[:=, :field1, "value1"], [:=, :field2, "value2"]]}

# OR query with nested AND
%{or: [[:=, :status, :new], %{and: [[:=, :status, :old], [:=, :age, 50]]}]}

That’s basically it. Check out the ExUnit tests to see if this could be useful to you.

https://github.com/maxohq/ets_select

Cheers!

6 Likes