clear with test.
This commit is contained in:
parent
8b978934c7
commit
276a183738
2 changed files with 17 additions and 7 deletions
|
@ -7,7 +7,7 @@
|
||||||
-module(ggs_db).
|
-module(ggs_db).
|
||||||
-import(mnesia).
|
-import(mnesia).
|
||||||
%-compile({no_auto_import,[length/2]}).
|
%-compile({no_auto_import,[length/2]}).
|
||||||
-export([init/0,setItem/4,getItem/3,removeItem/3,key/3,length/2]).
|
-export([init/0,setItem/4,getItem/3,removeItem/3,key/3,clear/2,length/2]).
|
||||||
-include("ggs_db.hrl").
|
-include("ggs_db.hrl").
|
||||||
|
|
||||||
%%-----------------------------------------------------
|
%%-----------------------------------------------------
|
||||||
|
@ -71,3 +71,14 @@ key(Db,Ns,Position) ->
|
||||||
end,
|
end,
|
||||||
{atomic, Ret} = mnesia:transaction(Fun),
|
{atomic, Ret} = mnesia:transaction(Fun),
|
||||||
Ret.
|
Ret.
|
||||||
|
|
||||||
|
|
||||||
|
clear(Db,Ns) ->
|
||||||
|
Fun = fun() ->
|
||||||
|
Keys = mnesia:all_keys(data),
|
||||||
|
Rest = lists:filter(fun({A,B,_}) -> ((A==Db) and (B==Ns)) end, Keys),
|
||||||
|
lists:map(fun({A,B,C}) -> removeItem(A,B,C) end, Rest)
|
||||||
|
end,
|
||||||
|
{atomic, Ret} = mnesia:transaction(Fun),
|
||||||
|
Ret.
|
||||||
|
|
||||||
|
|
|
@ -25,15 +25,14 @@ length_test() ->
|
||||||
removeItem_test() ->
|
removeItem_test() ->
|
||||||
ggs_db:removeItem(1,1,4),
|
ggs_db:removeItem(1,1,4),
|
||||||
?assertNot(ggs_db:getItem(1,1,4) =:= {atomic,"114"}).
|
?assertNot(ggs_db:getItem(1,1,4) =:= {atomic,"114"}).
|
||||||
%mnesia:stop().
|
|
||||||
|
|
||||||
key_test() ->
|
key_test() ->
|
||||||
?assert(ggs_db:key(1,1,2) =:= {1,1,3}),
|
?assert(ggs_db:key(1,1,2) =:= {1,1,3}).
|
||||||
|
|
||||||
|
clear_test() ->
|
||||||
|
ggs_db:clear(1,1),
|
||||||
|
?assert(ggs_db:length(1,1) =:= 0),
|
||||||
mnesia:stop().
|
mnesia:stop().
|
||||||
%cleanup(Val) ->
|
|
||||||
% mnesia:stop().
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%tests() ->
|
%tests() ->
|
||||||
% ggs_db_test().
|
% ggs_db_test().
|
||||||
|
|
Reference in a new issue