-module(wy).
-compile(export_all).
-record(users, {username, nickname, age}).
-include_lib("stdlib/include/ms_transform.hrl").
create_table()->
mnesia:create_schema(node()),
mnesia:start(),
mnesia:create_table(users, [{attributes, record_info(fields, users)}]).
test()->
Fun = fun()->
mnesia:write(#users{username = "John", nickname = "baddy", age = 25}),
mnesia:write(#users{username = "DaDa", nickname = "KaKa", age = 24}),
mnesia:write(#users{username = "Monk", nickname = "John", age = 24})
end,
mnesia:transaction(Fun),
Fun2 = ets:fun2ms(fun({users, UserName, NickName, Age}) when
UserName == "John" orelse NickName == "John" ->
{users, UserName, NickName, Age}
end),
mnesia:transaction(fun() -> mnesia:select(users, Fun2) end).