Skip to content

Instantly share code, notes, and snippets.

@teburd
Created December 3, 2011 15:03
Show Gist options
  • Save teburd/1427328 to your computer and use it in GitHub Desktop.
Save teburd/1427328 to your computer and use it in GitHub Desktop.
mnesia example
-module(person).
-export([init/0, insert/0, read/1]).
-record(person,
{name, %% atomic, unique key
age, %% age
married_to, %% name of partner or undefined
children }).%% list of children
init() ->
mnesia:create_table(person,[{attributes,record_info(fields,person)}]).
insert() ->
T = fun() ->
X = #person{name=john,
age=36,
married_to=ana,
children=[josh,kelly,samantha]
},
mnesia:write(X)
end,
mnesia:transaction(T).
read(Name) ->
R = fun() ->
mnesia:read(person,Name,write)
end,
mnesia:transaction(R).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment