Created
December 3, 2011 15:03
-
-
Save teburd/1427328 to your computer and use it in GitHub Desktop.
mnesia example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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