Skip to content

Instantly share code, notes, and snippets.

@ecin
Created May 20, 2009 06:43
Show Gist options
  • Save ecin/114663 to your computer and use it in GitHub Desktop.
Save ecin/114663 to your computer and use it in GitHub Desktop.
-module(matrix).
-export([do_this_once/0, update_cell/2, read_cell/2]).
%% index is a tuple: {user_id, article_id}
-record(cell, {index, value = 0 }).
do_this_once() ->
mnesia:create_schema([node()]),
mnesia:start(),
mnesia:create_table(cell,
[{attributes, record_info(fields, cell)},
{disc_copies, [node()]},
{type, set}]).
update_cell(User, Article) ->
Cell = #cell{index={User,Article},value=1},
F = fun() ->
mnesia:write(Cell)
end,
mnesia:transaction(F).
read_cell(User, Article) ->
F = fun() ->
mnesia:read({cell,{User,Article}})
end,
mnesia:transaction(F).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment