QLC power
I've been doing some more work on my query DSL (described in an earlier post) for an internal project at my work.
I had a number of 2GB sized Mnesia disk_only tables that I wanted to traverse in a QLC query as one single table. Writing a QLC handler solved that very nicely:
tables() ->
Tables = all_tables(),
TF = fun() -> next(Tables) end,
InfoFun = fun(keypos) -> 2;
(_) -> undefined
end,
qlc:table(TF, [{info_fun, InfoFun}]).
next([T|_] = Tables) ->
next(Tables, mnesia:dirty_first(T));
next([]) ->
[].
next([_|Ts], '$end_of_table') ->
next(Ts);
next([T|_] = Tables, Key) ->
[hd(mnesia:dirty_read(T, Key)) |
fun() -> next(Tables, mnesia:dirty_next(T,Key)) end];
next([], '$end_of_table') ->
[].
So now I can make QLC queries like:
[T#tab.name || T <- my:tables(), T#tab.age > 42]
Hurray for QLC!
--Tobbe
| 3 Jul 2009 (14:08:31) QLC power |
| 7 Apr 2009 (14:38:57) The importance of side-effect free coding |
| 7 Apr 2009 (04:37:26) Seethrough and Nitrogen |
| 21 Mar 2009 (01:57:05) RFC 4226 - HMAC-Based One-Time Password Algorithm |
| 8 Mar 2009 (00:32:33) The OTP docs. |
| 4 Mar 2009 (07:37:29) A frontend to xref |
| 20 Feb 2009 (09:23:50) Tracing with Redbug |
| 12 Feb 2009 (01:07:17) Erlang OpenID implementation |