How do I write a qlc query that traverses table until it finds the first matching entry? For instance, this query returns all entries in the table that match criteria:

qlc:q([E#stuff.data || E <- mnesia:table(stuff), E#stuff.type == 123]).

How to modify this or the qlc:e call to stop and return only the first matching entry? The motivation for this is performance - I'm not interested in all entries, just want to take a look at how entries of specific type look like.

有帮助吗?

解决方案

You need to use a qlc cursor and qlc:next_answers/2, take a look at the example in qlc:cursor/1. It should look something like

QH=qlc:q([E#stuff.data || E <- mnesia:table(stuff), E#stuff.type == 123]).
QC = qlc:cursor(QH).
Result=qlc:next_answers(QC, 1). % Only return 1 answer
qlc:delete_cursor(QC).
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top