anchor.diff:  delete(Type, Id) ->
   	mnesia:delete({Type, Id}).
   
  +search(Type, Params) ->
  +	Matchspec = make_matchspec(Type, Params),
  +	Recs = mnesia:select(Type, Matchspec),
  +	{ok, Recs}.
  +		
   %% @hidden
   transaction(Fun) ->
   	case mnesia:transaction(Fun) of
  
positive.code: -define(EXPECTED_TABLES, [schema, ?COUNTERS_TABLE]).
  
  -export([check_setup/0]).
  -export([transaction/1, save/1, get_by_id/2, delete/2]).
  
  %% @doc Ensure the mnesia schema and tables exist. Assumes a schema already
  %% exists.
  
negative.code: 	{atomic, ok} = mnesia:create_table(?COUNTERS_TABLE, []),
  	create_tables(Tail).
  
  make_matchspec(Table, Params) ->
  	Attributes = mnesia:table_info(Table, attributes),
  	Numbered = lists:zip(Attributes, lists:seq(1, length(Attributes))),
  	Dollared = lists:map(fun({Attr, N}) ->
  		NList = integer_to_list(N),
  		MatchAtom = list_to_atom("$" ++ NList),
  		{Attr, MatchAtom}
  	end, Numbered),
  	{_Attrs, DollaredAlone} = lists:unzip(Dollared),
  	MatchRec = list_to_tuple([Table | DollaredAlone]),
  	NormalParams = normalize_params(Params),
  	MatchSpecParams = make_match_guard(NormalParams, Dollared),
  	[{MatchRec, MatchSpecParams, ['$_']}].
  
  normalize_params(Params) ->
  	lists:map(fun normalize_param/1, Params).
  
  normalize_param({Key, Value}) -> {Key, '==', Value};
  normalize_param(P) -> P.
  
  make_match_guard(In, Atoms) ->
  	FilteredIn = lists:filter(fun({Key, _, _}) ->
  		case proplists:get_value(Key, Atoms) of
  			undefined -> false;
  			_ -> true
  		end
  	end, In),
  	lists:map(fun({Key, Op, Arg}) ->
  		Atom = proplists:get_value(Key, Atoms),
  		{Op, Atom, Arg}
  	end, FilteredIn).
  
  