Hi!
I’m trying to use Mnesia as the database for my small project and I’m currently trying to implement a cursor based pagination following this article: https://medium.com/@george_16060/cursor-based-pagination-with-arbitrary-ordering-b4af6d5e22db
At the moment, I’m stuck trying to get Mnesia to order a simple query by 2 fields, even though I got it working for one. My current implementation looks like this:
QH1 = qlc:q([Product || Product <- mnesia:table(product)]),
QH2 = qlc:sort(QH1, [{order,
fun(A, B) ->
(product:get_quantity(A) >= product:get_quantity(B))
and (product:get_id(A) >= product:get_id(B))
end}]),
Rows = qlc:eval(QH2)
The sorting function is literally the same I used in my tests to order a list of products, but that time using lists:sort
, which seems to be working as expected.
Am I doing something wrong or there is a reason why qlc
is not able to sort by several fields? Is this a limitation of Mnesia somehow?
Thank you all!