3.3. Erlang
The Erlang query server is disabled by default. Read configuration guide about reasons why and how to enable it.
(Id, Value)
Emits key-value pairs to view indexer process.
FoldRows
(Fun, Acc)
Helper to iterate over all rows in a list function.
-
Fun – Function object.
Acc – The value previously returned by Fun.
fun(Head, {Req}) ->
Fun = fun({Row}, Acc) ->
Id = couch_util:get_value(<<"id">>, Row),
Send(list_to_binary(io_lib:format("Previous doc id: ~p~n", [Acc]))),
Send(list_to_binary(io_lib:format("Current doc id: ~p~n", [Id]))),
{ok, Id}
end,
FoldRows(Fun, nil),
end.
()
Retrieves the next row from a related view result.
Log
(Msg)
-
- Msg – Log a message at the INFO level.
fun({Doc}) ->
<<K,_/binary>> = proplists:get_value(<<"_rev">>, Doc, null),
V = proplists:get_value(<<"_id">>, Doc, null),
Log(lists:flatten(io_lib:format("Hello from ~s doc!", [V]))),
Emit(<<K>>, V)
end.
After the map function has run, the following line can be found in CouchDB logs (e.g. at /var/log/couchdb/couch.log):
Send
(Chunk)
Sends a single string Chunk in response.
fun(Head, {Req}) ->
Send("Hello,"),
"!"
end.
The function above produces the following response:
Start
(Headers)
-
- Headers – Proplist of .
Initialize List Functions response. At this point, response code and headers may be defined. For example, this function redirects to the CouchDB web site:
fun(Head, {Req}) ->
Start({[{<<"code">>, 302},
{<<"headers">>, {[
{<<"Location">>, <<"http://couchdb.apache.org">>}]
}}
]}),
end.