These are chat archives for synrc/n2o

17th
Jan 2016
Ram Kumar
@ramka001
Jan 17 2016 16:15
Hi does kvs have an alternative for qlc to query something like this:
module(db_utils)
.
.
.

do(Q) ->
    F = fun() -> qlc:e(Q) end,
    case mnesia:transaction (F) of
    {atomic, Val} ->
        Val;
    {aborted, Reason} ->
        io:format("Query: ~w aborted.~nReason: ~w~n", [Q, Reason]),
        aborted
    end.

 case db_utils:do (qlc:q ([X#users.username ||  X <- mnesia:table(users), check(X#users.username, X#users.email_address, Username), X#users.password == PasswordDigest])) of
    fail ->
        {aborted, "Not valid"};
        Results ->
            if length (Results) == 1 ->
            %% update the last logged in time
            case update_last_logged_in(Username) of
            {atomic, ok} ->
                {valid, hd(Results)};
            {aborted, _} ->
                io:format("Error: Unable to update last_logged_in for user ~s~n", [Username]),
                {aborted, "Not valid"}
            end;
        true ->
            {aborted, "Not valid"}
        end
    end.
tried using store_mnesia:exec also