mindreframer

mindreframer

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!

Most Liked

axelson

axelson

Scenic Core Team

Oooh, another match spec library! I definitely welcome alternative DSLs in the space.

Are you interested in adding more support for keys that are tuples? For example in my data_tracer library I insert data that looks roughly like:

{{1723901292213, 0, "age"}, "100"}
{{1723901292214, 0, "age"}, "101"}
{{1723901292214, 0, "name"}, "bob"}

And I want to do a query to get all the values where the third element in the tuple key is "age", i.e. something like :ets.select(:my_table, match_spec) == ["100", "101"]. From what I can tell this isn’t currently possible to query via ets_select, is that right?

I also submitted a quick PR to remove the test files from the published package: Exclude test files from published package by axelson · Pull Request #1 · maxohq/ets_select · GitHub

mindreframer

mindreframer

@axelson I went ahead and dropped matcha in this PR: Feat: drop `matcha` package by mindreframer · Pull Request #5 · axelson/data_tracer · GitHub

It should be 100% exact behaviour, just without all the non-trivial abstractions provided by GitHub - christhekeele/matcha: 🍵 First-class Elixir match specifications. · GitHub.

If you want a proper query language, this should be done separately.

Have a good Saturday!

mindreframer

mindreframer

@axelson Thanks for the encouragement!

While it could be possible, it would change the original goal of the package. It seems you are storing arbitrary values for debugging in data_tracer, yet my use case is selecting based on field values in maps / structs.

BTW, GitHub - axelson/data_tracer: Elixir library to facilitate debugging data flow, helps capture terms for later inspection · GitHub looks awesome, gonna try it out soon. If you want to have a query language for data_tracer, please give some example queries. IF your only query type is selecting on the 3rd element of the key tuple, there is probably no need for a 3rd-party library :slight_smile:

The spec to match all elements with “age” OR “name” would look like this:

match_spec = [
    {{{:_, :_, :"$3"}, :_}, [{:orelse, {:==, :"$3", "age"}, {:==, :"$3", "name"}}], [:"$_"]}
]

So, please share some examples, maybe I could contribute a query language just for data_tracer, that would be most simple and direct approach.

Last Post!

AstonJ

AstonJ

8 posts were split to a new topic: Split from EtsSelect thread

Where Next?

Popular in Announcing Top

alisinabh
Hey everyone i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
tmbb
I’ve decided to create this topic to discuss optimization possibilities for something like Phoenix LiveView. I’ve created this topic unde...
144 10789 141
New
RobertDober
Earmark is a pure-Elixir Markdown converter. It is intended to be used as a library (just call Earmark.as_html), but can also be used as...
239 12888 134
New
maltoe
Hello! Came here to announce ChromicPDF, a pet project PDF generator I’ve been working on for the past few months. Why another PDF gener...
New
kevinlang
Hey all, We have made an Ecto3 Adapter for SQLite3, ecto_sqlite3! We have successfully on-boarded the full suite of integration tests (...
New
tfwright
After working on it for a couple of months and using it in production for most of that time, today I’ve released LiveAdmin, a LiveView ba...
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 10719 134
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49084 226
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement