|
@@ -25,6 +25,20 @@ handle('GET',[<<"db">>], Req) ->
|
|
|
{result_packet, _, _, [[ID, Rand]], _} <- [emysql:execute(test_pool, db_stmt, [random:uniform(10000)]) || _ <- lists:seq(1, I) ]],
|
|
|
Res
|
|
|
end,
|
|
|
+ {ok, [{<<"Content-Type">>, <<"application/json">>}], jiffy:encode(lists:nth(1,JSON))};
|
|
|
+
|
|
|
+handle('GET',[<<"query">>], Req) ->
|
|
|
+ random:seed(erlang:now()),
|
|
|
+ JSON = case elli_request:get_arg(<<"queries">>, Req) of
|
|
|
+ undefined ->
|
|
|
+ {result_packet, _, _, [[ID, Rand]], _} = emysql:execute(test_pool, db_stmt, [random:uniform(10000)]),
|
|
|
+ [{[{<<"id">>, ID}, {<<"randomNumber">>, Rand}]}];
|
|
|
+ N ->
|
|
|
+ I = list_to_integer(binary_to_list(N)),
|
|
|
+ Res = [ {[{<<"id">>, ID}, {<<"randomNumber">>, Rand}]} ||
|
|
|
+ {result_packet, _, _, [[ID, Rand]], _} <- [emysql:execute(test_pool, db_stmt, [random:uniform(10000)]) || _ <- lists:seq(1, I) ]],
|
|
|
+ Res
|
|
|
+ end,
|
|
|
{ok, [{<<"Content-Type">>, <<"application/json">>}], jiffy:encode(JSON)};
|
|
|
|
|
|
handle(_, _, _Req) ->
|