Created
January 22, 2014 18:18
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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