Hi,
I am new to Erlang. I am writing escript which makes database related operations. I list the records by using mnesia:foldl
method as follows;
select_all(RemoteNode, TableName) ->
%% enumerate the records in a specific table
rpc:call( RemoteNode, mnesia, transaction, [
fun() -> mnesia:foldl(
fun(Rec,_Acc) -> io:format("~p\n",[Rec]) end,
[],
TableName)
end
]).
But this method returns list in tuple format. I want to listen records with corresponding field names.
After exploring the approach, I only find the following ;
-module('foo').
-author('Mats Cronqvist').
-export([go/0]).
-define(rec_info(T,R),lists:zip(record_info(fields,T),tl(tuple_to_list(R)))).
-record(r,{bla,foo,baz,bar}).
go() -> ?rec_info(r,#r{}).`
> Result -> foo:go().
> [{bla,undefined},
> {foo,undefined},
> {baz,undefined},
> {bar,undefined}]
I couldn’t understand the syntax of the method stated above. So I couldn’t manage to apply it to my script.
How can I display the records with field names ?
Thanks in advance,