[erlang-questions] Mnesia dynamic table creation

zambal <>
Thu Nov 6 13:15:34 CET 2008


Since records are in fact tupples, just use tupples instead of
records.

Example:

Eshell V5.6.5  (abort with ^G)
1> mnesia:create_schema([node()]).
ok
2> mnesia:start().
ok
3> mnesia:create_table(my_doc, [{attributes, [title, author, tags,
body]}]).
{atomic,ok}
4> mnesia:transaction(fun()-> mnesia:write({my_doc, "my first doc",
"vincent", ["example", "programming"], "blah blah blah blah ..."})
end).
{atomic,ok}
5> mnesia:transaction(fun()-> qlc:e(qlc:q([X || X <-
mnesia:table(my_doc)])) end).
{atomic,[{my_doc,"my first doc","vincent",
                 ["example","programming"],
                 "blah blah blah blah ..."}]}

The only downside of this is that you can not use the records syntax
for extracting individual fields from the resulting tupples.

---
vincent



On 5 nov, 23:15, "Jose Enrique Benitez Jimenez"
<> wrote:
> Hello, I was study mnesia, and so far I dont know how to create a table in run-time, because the records most be set in the code before I compile it, How can I do that?
>
> Thank you very much.
>
> _______________________________________________
> erlang-questions mailing list
> ://www.erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list