-
Notifications
You must be signed in to change notification settings - Fork 0
/
swarm_mnesia.erl
66 lines (47 loc) · 1.45 KB
/
swarm_mnesia.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
%% @author J.R. Bedard <jrbedard@gmail.com>
%% @copyright 2008 jrbedard.
%% @doc TEMPLATE.
-module(swarm_mnesia).
-author('jrbedard <jrbedard@gmail.com>').
-include_lib("stdlib/include/qlc.hrl").
-include("swarm_schema.hrl").
-export([do/1, start/0, stop/0]).
start() ->
mnesia:create_schema([node()]),
mnesia:start(),
reset_table(),
init(),
%%mnesia:wait_for_tables([],90000),
%% test data.
insert_test_data().
insert_test_data() ->
swarm_people:insert_test_data(),
swarm_events:insert_test_data(),
swarm_locations:insert_test_data().
stop() ->
mnesia:stop().
reset_table() ->
mnesia:clear_table(person),
mnesia:clear_table(location),
mnesia:clear_table(event).
do(Q) ->
F = fun() -> qlc:e(Q) end,
{atomic, Val} = mnesia:transaction(F),
Val.
init() ->
mnesia:create_table(person,
[{attributes, record_info(fields, person)},
{ram_copies, [node()]},
{type, bag}]),
mnesia:create_table(location,
[{attributes, record_info(fields, location)},
{ram_copies, [node()]},
{type, bag}]),
mnesia:create_table(event,
[{attributes, record_info(fields, event)},
{ram_copies, [node()]},
{type, bag}]),
mnesia:create_table(p_at_loc, [{type, bag},
{ram_copies, [a@gin, b@skeppet]},
{attributes, record_info(fields,
p_at_loc)}]).