Skip to content

Instantly share code, notes, and snippets.

@brailateo
Created January 22, 2014 18:18
Show Gist options
  • Save brailateo/8564221 to your computer and use it in GitHub Desktop.
Save brailateo/8564221 to your computer and use it in GitHub Desktop.
LIST function for CouchDB - extracting information from a view (or from _all_docs) in order to be returned as a JSON data well formed, suitable for an aaData data source for a DataTable in browser
fun(Head, {Req}) ->
Send(<<"[">>),
Fun = fun({Row}, Virgula) ->
Send(Virgula),
case proplists:get_value(<<"doc">>, Row) of
{Doc} ->
Elocalitate = proplists:is_defined(<<"Siruta">>, Doc),
if
Elocalitate ->
Send(<<"[\"">>),
Send(proplists:get_value(<<"id">>, Row)),
Send(<<"\",\"">>),
Send(proplists:get_value(<<"Nume">>, Doc)),
Send(<<"\",\"">>),
Send(proplists:get_value(<<"Siruta">>, Doc)),
Send(<<"\",\"">>),
Send(proplists:get_value(<<"Județ">>, Doc)),
Send(<<"\"]">>),
{ok, <<",">>};
true ->
{ok,Virgula}
end;
_ ->
{ok, <<",">>}
end
end,
{ok, _} = FoldRows(Fun, <<"">>),
<<"]">>
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment