length(Db,Ns) and tests for get,set and length.

This commit is contained in:
Kallfaktorn 2011-02-21 22:31:25 +01:00
parent ee4059ac5a
commit e55e0bd8a3
2 changed files with 18 additions and 3 deletions

View file

@ -6,7 +6,8 @@
-module(ggs_db).
-import(mnesia).
-export([init/0,setItem/4,getItem/3]).
%-compile({no_auto_import,[length/2]}).
-export([init/0,setItem/4,getItem/3,length/2]).
-include("ggs_db.hrl").
%%-----------------------------------------------------
@ -45,3 +46,10 @@ getItem(Db,Ns,Key) ->
end,
mnesia:transaction(Fun).
length(Db,Ns) ->
Fun = fun() ->
Keys = mnesia:all_keys(data),
length(lists:filter(fun({A,B,_}) -> ((A==Db) and (B==Ns)) end, Keys))
end,
{atomic, Ret} = mnesia:transaction(Fun),
Ret.