Anyone using joins in Amnesia (Elixir Mnesia wrapper)

Whatever your opinion of Mnesia is, has anyone used joins via qlc - query list comprehension - in an Elixir form?

It appears based on this thread that qlc operates on Erlang style list comprehensions instead of Elixir style. I noticed this Qlc library but this is also Erlang style.

Just curious if anyone has tried this out in Elixir and curious as to the build steps. Without being able to join tables here with qlc wondering how people are joining tables in Mnesia land…

Here’s some erlang qlc from the mnesia chapter of Programming Erlang

do(qlc:q([X#shop.item || X <- mnesia:table(shop),
                                   X#shop.quantity < 250,
                                   Y <- mnesia:table(cost),
                                   X#shop.item =:=,
                                   Y#cost.price < 2

and the equivalent SQL

SELECT shop.item, shop.quantity,, cost.price
FROM shop, cost
WHERE shop.item =
  AND cost.price < 2
  AND shop.quantity < 250

Perhaps this is the way to go about querying via the Ecto Mnesia adapter ???

Automatically converts Ecto.Query structs to Erlang match_spec. Also adapter emulates and query.order_bys behaviours, even though Mnesia itself does not support them.

1 Like

Upon further read, it looks like Amnesia supports this, just need to figure out how to go about using the selection constructs with join

  # You can also use an Exquisite selector to fetch records.
  selection = Message.where user_id == 1 or user_id == 2,
    select: content

  # Get the values in the selector and print them.
  selection |> Amnesia.Selection.values |> Enum.each &IO.puts(&1.content)
1 Like

Does this code actually works ? For me, it’s not. My frustation with Amnesia library is growing… in Erlang it’s working so smoothly :confused: