Tag Archive: mensia

Provided that you want to increase or update the field YOUR_UPDATE_FIELD in table YOUR_TABLE with a key YOUR_TABLE_KEY_VALUE,
just use the following codes.

Query =
fun() ->
[OldRecord] = mnesia:read(YOUR_TABLE, YOUR_TABLE_KEY_VALUE, write),
P = OldRecord#YOUR_TABLE.YOUR_UPDATE_FIELD + 1,
NewRecord = OldRecord#operator{ YOUR_UPDATE_FIELD = P },
mnesia:write(NewRecord)
end,
{atomic, Result} = mnesia:transaction(Query).

Q1 = qlc:q([X || X <- mnesia:table(YOUR_TABLE)]),
{atomic,T1} = mnesia:transaction(fun()->qlc:eval(Q1)  end),
T1.

Replace YOUR_TABLE with the table name of your mnesia table,
insert the code above in your erlang module,
you will get the data in T1.