key with test.
This commit is contained in:
parent
c66d1cef69
commit
8b978934c7
2 changed files with 14 additions and 4 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,length/2]).
|
||||
-export([init/0,setItem/4,getItem/3,removeItem/3,key/3,length/2]).
|
||||
-include("ggs_db.hrl").
|
||||
|
||||
%%-----------------------------------------------------
|
||||
|
@ -63,4 +63,11 @@ length(Db,Ns) ->
|
|||
{atomic, Ret} = mnesia:transaction(Fun),
|
||||
Ret.
|
||||
|
||||
|
||||
key(Db,Ns,Position) ->
|
||||
Fun = fun() ->
|
||||
Keys = mnesia:all_keys(data),
|
||||
Rest = lists:filter(fun({A,B,_}) -> ((A==Db) and (B==Ns)) end, Keys),
|
||||
lists:nth(Position, Rest)
|
||||
end,
|
||||
{atomic, Ret} = mnesia:transaction(Fun),
|
||||
Ret.
|
||||
|
|
|
@ -24,9 +24,12 @@ length_test() ->
|
|||
|
||||
removeItem_test() ->
|
||||
ggs_db:removeItem(1,1,4),
|
||||
?assertNot(ggs_db:getItem(1,1,4) =:= {atomic,"114"}),
|
||||
mnesia:stop().
|
||||
?assertNot(ggs_db:getItem(1,1,4) =:= {atomic,"114"}).
|
||||
%mnesia:stop().
|
||||
|
||||
key_test() ->
|
||||
?assert(ggs_db:key(1,1,2) =:= {1,1,3}),
|
||||
mnesia:stop().
|
||||
%cleanup(Val) ->
|
||||
% mnesia:stop().
|
||||
|
||||
|
|
Reference in a new issue