Compare commits
No commits in common. "3c40cc381e1413d28149f6f8f3ed35d402406786" and "5b73df899939708029d8adc0c90e0f21f79fa00c" have entirely different histories.
3c40cc381e
...
5b73df8999
|
@ -18,7 +18,7 @@
|
||||||
-include_lib("dudeswave_backend/include/defines.hrl").
|
-include_lib("dudeswave_backend/include/defines.hrl").
|
||||||
-include_lib("storage/include/storage.hrl").
|
-include_lib("storage/include/storage.hrl").
|
||||||
|
|
||||||
-export([details/2, new/4, update/5, delete/2]).
|
-export([details/2, new/4, update/5, delete/1]).
|
||||||
|
|
||||||
-doc """
|
-doc """
|
||||||
Return user details.
|
Return user details.
|
||||||
|
@ -136,19 +136,17 @@ update(User, Host, Name, Email, Desc) ->
|
||||||
Delete an existing user from the database.
|
Delete an existing user from the database.
|
||||||
|
|
||||||
```
|
```
|
||||||
-spec delete(User, Host) -> ok | {error, Reason} when
|
-spec delete(User) -> ok | {error, Reason} when
|
||||||
User :: binary(),
|
User :: binary(),
|
||||||
Host :: binary(),
|
|
||||||
Reason :: term().
|
Reason :: term().
|
||||||
```
|
```
|
||||||
""".
|
""".
|
||||||
-spec delete(User, Host) -> ok | {error, Reason} when
|
-spec delete(User) -> ok | {error, Reason} when
|
||||||
User :: binary(),
|
User :: binary(),
|
||||||
Host :: binary(),
|
|
||||||
Reason :: term().
|
Reason :: term().
|
||||||
|
|
||||||
delete(User, Host) ->
|
delete(User) ->
|
||||||
ComplUser = <<User/binary, "@", Host/binary>>,
|
% We are missing the cleanup of the cookies
|
||||||
|
% here. For that, we need to add at least another
|
||||||
ok = storage:delete(?USERSBUCK, ComplUser),
|
% API to the storage layer.
|
||||||
ok = storage:delete_set(?COOKIESBUCK, [{user, ComplUser}]).
|
storage:delete(?USERSBUCK, User).
|
||||||
|
|
|
@ -53,7 +53,7 @@ file:
|
||||||
shrink/2]).
|
shrink/2]).
|
||||||
|
|
||||||
% Public record operation functions
|
% Public record operation functions
|
||||||
-export([delete/2, delete_set/2, list/2, read/2, write/3, write/4]).
|
-export([delete/2, list/2, read/2, write/3, write/4]).
|
||||||
|
|
||||||
% Module callbacks
|
% Module callbacks
|
||||||
-export([code_change/3,
|
-export([code_change/3,
|
||||||
|
@ -462,30 +462,6 @@ Spec:
|
||||||
delete(Bucket, Key) ->
|
delete(Bucket, Key) ->
|
||||||
gen_server:call(?MODULE, {delete, Bucket, Key}).
|
gen_server:call(?MODULE, {delete, Bucket, Key}).
|
||||||
|
|
||||||
-doc """
|
|
||||||
Delete a set of records based on the given metadata list.
|
|
||||||
|
|
||||||
Spec:
|
|
||||||
|
|
||||||
```
|
|
||||||
-spec delete_set(Bucket, Metadata) -> ok | {error, Reason} when
|
|
||||||
Bucket :: atom(),
|
|
||||||
Metadata :: [{Key, Value}],
|
|
||||||
Key :: term(),
|
|
||||||
Value :: term(),
|
|
||||||
Reason :: term().
|
|
||||||
```
|
|
||||||
""".
|
|
||||||
-spec delete_set(Bucket, Metadata) -> ok | {error, Reason} when
|
|
||||||
Bucket :: atom(),
|
|
||||||
Metadata :: [{Key, Value}],
|
|
||||||
Key :: term(),
|
|
||||||
Value :: term(),
|
|
||||||
Reason :: term().
|
|
||||||
|
|
||||||
delete_set(Bucket, Metadata) ->
|
|
||||||
gen_server:call(?MODULE, {delete_set, Bucket, Metadata}).
|
|
||||||
|
|
||||||
-doc """
|
-doc """
|
||||||
Spec:
|
Spec:
|
||||||
|
|
||||||
|
@ -728,20 +704,6 @@ handle_call({delete, Bucket, Key}, _From, State) ->
|
||||||
{aborted, Reason} -> {reply, {error, Reason}, State}
|
{aborted, Reason} -> {reply, {error, Reason}, State}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
handle_call({delete_set, Bucket, Metadata}, _From, State) ->
|
|
||||||
Q = qlc:q([X || X <- mnesia:table(Bucket), filter(Metadata, X#object.metadata)]),
|
|
||||||
|
|
||||||
F = fun() ->
|
|
||||||
Recs = qlc:e(Q),
|
|
||||||
|
|
||||||
delete_matching(Bucket, Recs)
|
|
||||||
end,
|
|
||||||
|
|
||||||
case mnesia:transaction(F) of
|
|
||||||
{atomic, ok} -> {reply, ok, State};
|
|
||||||
{aborted, Reason} -> {reply, {error, Reason}, State}
|
|
||||||
end;
|
|
||||||
|
|
||||||
handle_call({write, Bucket, Key, Term}, _From, State) ->
|
handle_call({write, Bucket, Key, Term}, _From, State) ->
|
||||||
handle_call({write, Bucket, Key, Term, []}, _From, State);
|
handle_call({write, Bucket, Key, Term, []}, _From, State);
|
||||||
|
|
||||||
|
@ -829,12 +791,4 @@ filter([H | T], M) ->
|
||||||
Val =:= V -> filter(T, M);
|
Val =:= V -> filter(T, M);
|
||||||
true -> false
|
true -> false
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%
|
|
||||||
% Delete all the records in a table for every key in the list.
|
|
||||||
%
|
|
||||||
delete_matching(_Bucket, []) -> ok;
|
|
||||||
delete_matching(Bucket, [H | T]) ->
|
|
||||||
mnesia:delete(Bucket, H#object.key),
|
|
||||||
delete_matching(Bucket, T).
|
|
Loading…
Reference in New Issue