mindreframer
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. ![]()
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!
Trending in Announcing
Hey everyone!
Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application.
This library uses Erlang esaml to provide
plug enabl...
New
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries.
offset-based pagination with...
New
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi all!
I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas.
You...
New
Hello
Published a new library - ProcessHub!
ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
This showed up on my feed.. anyone heard of it? Just hype?
Ox Alpha is a reasoning model designed for coding, sustained ag...
New
It’s not that it’s vocabulary is too advanced. It’s something worse.
I get lost trying to follow even a paragraph written by Claude. It’...
New
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
axelson
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:
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 viaets_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
@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
The spec to match all elements with “age” OR “name” would look like this:
So, please share some examples, maybe I could contribute a query language just for data_tracer, that would be most simple and direct approach.
mindreframer
It seems the only place where you execute a query on ETS tables is this
Exactly this query should be covered by this spec:
Example:
So… In theory you could drop your dependency on
Matcha.mindreframer
@axelson I went ahead and dropped
matchain this PR: Feat: drop `matcha` package by mindreframer · Pull Request #5 · axelson/data_tracer · GitHubIt 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!
axelson
Fair enough! All libraries need to define the scope that they want to tackle
Thank you for the kind words! I don’t have a plan to add a query language for data_tracer, the use case is mainly getting stored values out ordered by insertion and only for specific keys. For my usage of it I probably don’t even need to worry about efficient ETS lookups and could instead dump the whole table and filter it, but I wanted to take it as an opportunity to work with ETS in a more efficient manner.
Thank you for the contribution! I’ve merged the PR and released it as version 0.1.2
The reason matcha was even there was two fold: I wanted an excuse to try out Matcha, and I find match specs inscrutable to the point where I’m not super interested in learning them.
mindreframer
@axelson
Yeah, the specs are really painful to read / write / understand. But… Just after having implemented he EtsSelect package, it was bearable to come up this those 2 match-specs. And having less dependencies is always nice
Thanks for merging the PR!
@dimitarvp Yeah, I’m quite familiar with the great, even outstanding quality of Elixir docs. I just dont need to lookup something, that is already working
Only when things dont behave as expected, I dig deeper. So 100% agree with you on this one.
Thanks for chiming in and good night (its about midnight in EU)!