Permalink
Browse files

Refactored get methods.

  • Loading branch information...
1 parent 75d911b commit b7d2fb86c882b24d51c1f208be7fb3456c69aad3 @baphled committed Mar 21, 2009
Showing with 22 additions and 9 deletions.
  1. +22 −9 lib/chatterl/src/chatterl_store.erl
@@ -154,9 +154,7 @@ user(User) ->
%% @end
%%--------------------------------------------------------------------
get_group(GroupName) ->
- F = fun() -> qlc:e(qlc:q([X || X <- mnesia:table(group), X#group.name =:= GroupName])) end,
- {atomic,Result} = mnesia:transaction(F),
- Result.
+ get(group,GroupName).
%%--------------------------------------------------------------------
%% @doc
@@ -166,14 +164,17 @@ get_group(GroupName) ->
%% @end
%%--------------------------------------------------------------------
get_user(ClientName) ->
- F = fun() -> qlc:e(qlc:q([X || X <- mnesia:table(client), X#client.name =:= ClientName])) end,
- {atomic,Result} = mnesia:transaction(F),
- Result.
+ get(client,ClientName).
+%%--------------------------------------------------------------------
+%% @doc
+%% Retrieves a registered users.
+%%
+%% @spec get_registered(User) -> GroupState
+%% @end
+%%--------------------------------------------------------------------
get_registered(User) ->
- F = fun() -> mnesia:read({registered_user,User}) end,
- {atomic,Result} = mnesia:transaction(F),
- Result.
+ get(registered_user,User).
%%====================================================================
%% gen_server callbacks
@@ -277,3 +278,15 @@ create_user(Nickname,{User,Email,Password}) ->
{aborted,Result};
_ -> {ok,lists:append(Nickname," is registered")}
end.
+
+%%--------------------------------------------------------------------
+%% @doc
+%% Retrieves a single record from a table
+%%
+%% @spec group(Table,Value) -> [{TableRecord}] | []
+%% @end
+%%--------------------------------------------------------------------
+get(Table,Value) ->
+ F = fun() -> mnesia:read({Table,Value}) end,
+ {atomic,Result} = mnesia:transaction(F),
+ Result.

0 comments on commit b7d2fb8

Please sign in to comment.