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).
|
||||
-import(mnesia).
|
||||
%-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").
|
||||
|
||||
%%-----------------------------------------------------
|
||||
|
@ -71,3 +71,14 @@ key(Db,Ns,Position) ->
|
|||
end,
|
||||
{atomic, Ret} = mnesia:transaction(Fun),
|
||||
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.
|
||||
|
||||
|
|
Reference in a new issue