Created
May 11, 2009 09:59
-
-
Save daniello/109936 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bs_by_a_id(A_id) -> | |
find(qlc:q([ B || B=#b{f_id=F_id} <- mnesia:table(b), F_id == A_id])). | |
as_with_bs() -> | |
find( | |
qlc:q([ {A,bs_by_a_id(A#a.id)} || A <- mnesia:table(a)]) | |
). | |
top_as_with_some_bs(Limit) -> | |
top( | |
qlc:q([ {A,bs_by_a_id(A#a.id)} || A <- mnesia:table(a)]), | |
Limit, | |
fun(A1,A2) -> A1 < A2 end | |
). | |
% --- utils | |
find(Q) -> | |
F = fun() -> qlc:e(Q) end, | |
transaction(F). | |
% --- it returns top Limit results from query Q ordered by Order sort function | |
top(Q, Limit, Order) -> | |
{atomic, Res} = mnesia:transaction(fun() -> | |
OQ = qlc:sort(Q, [{order,Order}]), | |
QC = qlc:cursor(OQ), | |
Res = qlc:next_answers(QC, Limit), | |
qlc:delete_cursor(QC), | |
Res | |
end), | |
Res. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment