moving from mnesia to ets. matchspecs are complicated when dates and atoms are involved.
This commit is contained in:
@@ -4,8 +4,19 @@
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
|
||||
-export([zones/1, rules/1, flatzones/1, flatzone/2]).
|
||||
-export([wipe/0, wipe/1, init/0, insert_all/1, get_all/1]).
|
||||
-export([
|
||||
zones/1
|
||||
, rules/1
|
||||
, flatzone/2
|
||||
]).
|
||||
|
||||
-export([
|
||||
wipe/0
|
||||
, wipe/1
|
||||
, init/0
|
||||
, insert_all/1
|
||||
, get_all/1
|
||||
]).
|
||||
|
||||
|
||||
-define(create(Record),
|
||||
@@ -50,17 +61,14 @@ get_all(Tab) when is_atom(Tab) ->
|
||||
{atomic, Ret}= mnesia:transaction(F),
|
||||
Ret.
|
||||
|
||||
|
||||
flatzones(TzName) ->
|
||||
F = fun() ->
|
||||
Q = qlc:q([Fz || Fz=#flatzone{tzname=N}<- mnesia:table(flatzone), N=:=TzName]),
|
||||
qlc:e(Q)
|
||||
end,
|
||||
{atomic, Ret}= mnesia:transaction(F),
|
||||
Ret.
|
||||
|
||||
|
||||
%% get a flatzone for a specific date
|
||||
%% Date :: {date(), #tztime{}}
|
||||
%% returns #flatzone{}
|
||||
%% or throws either error:
|
||||
%% * {ambiguous_zone, [Z1,Z2,...]}
|
||||
%% * {no_zone}
|
||||
flatzone(Date, TzName) ->
|
||||
%% @todo validate Date
|
||||
F = fun()->
|
||||
Q = qlc:q(
|
||||
[Fz || Fz=#flatzone{tzname=N} <- mnesia:table(flatzone)
|
||||
@@ -82,22 +90,6 @@ flatzone(Date, TzName) ->
|
||||
end.
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% WRITE - insertion/edit methods
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
insert_all(Records) ->
|
||||
mnesia:transaction(
|
||||
fun() ->
|
||||
lists:foreach(
|
||||
fun(R)-> mnesia:write(R) end,
|
||||
Records)
|
||||
end).
|
||||
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% ADMIN - initialization and administration methods
|
||||
@@ -143,5 +135,15 @@ create_tabs(E) ->
|
||||
?debugVal(E).
|
||||
|
||||
|
||||
insert_all(Records) ->
|
||||
mnesia:transaction(
|
||||
fun() ->
|
||||
lists:foreach(
|
||||
fun(R)-> mnesia:write(R) end,
|
||||
Records)
|
||||
end).
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user