From 2cf4fec22fa7214b11363eb7430c411e0afa6221 Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Sat, 1 Aug 2009 11:16:36 +0000 Subject: enable include_docs=true for list functions, patch by Mark Hammond, closes COUCHDB-444 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@799835 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/test/list_views.js | 10 ++++++++++ src/couchdb/couch_httpd_show.erl | 10 +++++----- src/couchdb/couch_query_servers.erl | 8 ++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/share/www/script/test/list_views.js b/share/www/script/test/list_views.js index 6ad5c6bc..4b089bac 100644 --- a/share/www/script/test/list_views.js +++ b/share/www/script/test/list_views.js @@ -160,6 +160,12 @@ couchTests.list_views = function(debug) { var row = getRow(); send(fooBarBam); // intentional error return "tail"; + }), + docReference : stringFun(function(head, req) { + send("head"); + var row = getRow(); + send(row.doc.integer); + return "tail"; }) } }; @@ -316,6 +322,10 @@ couchTests.list_views = function(debug) { T(/ReferenceError/.test(xhr.responseText)); + // with include_docs and a reference to the doc. + var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/docReference/basicView?include_docs=true"); + T(xhr.responseText.match(/head0tail/)); + // now with extra qs params var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/qsParams/basicView?foo=blam"); T(xhr.responseText.match(/blam/)); diff --git a/src/couchdb/couch_httpd_show.erl b/src/couchdb/couch_httpd_show.erl index a73105b4..40f0dc11 100644 --- a/src/couchdb/couch_httpd_show.erl +++ b/src/couchdb/couch_httpd_show.erl @@ -207,18 +207,18 @@ start_list_resp(QueryServer, Req, Db, Head, Etag) -> {ok, Resp, ?b2l(?l2b(Chunks))}. make_map_send_row_fun(QueryServer) -> - fun(Resp, Db, Row, _IncludeDocs, RowFront) -> - send_list_row(Resp, QueryServer, Db, Row, RowFront) + fun(Resp, Db, Row, IncludeDocs, RowFront) -> + send_list_row(Resp, QueryServer, Db, Row, RowFront, IncludeDocs) end. make_reduce_send_row_fun(QueryServer, Db) -> fun(Resp, Row, RowFront) -> - send_list_row(Resp, QueryServer, Db, Row, RowFront) + send_list_row(Resp, QueryServer, Db, Row, RowFront, false) end. -send_list_row(Resp, QueryServer, Db, Row, RowFront) -> +send_list_row(Resp, QueryServer, Db, Row, RowFront, IncludeDoc) -> try - [Go,Chunks] = couch_query_servers:render_list_row(QueryServer, Db, Row), + [Go,Chunks] = couch_query_servers:render_list_row(QueryServer, Db, Row, IncludeDoc), Chunk = RowFront ++ ?b2l(?l2b(Chunks)), send_non_empty_chunk(Resp, Chunk), case Go of diff --git a/src/couchdb/couch_query_servers.erl b/src/couchdb/couch_query_servers.erl index 1d452796..bb0cc853 100644 --- a/src/couchdb/couch_query_servers.erl +++ b/src/couchdb/couch_query_servers.erl @@ -19,7 +19,7 @@ -export([start_doc_map/2, map_docs/2, stop_doc_map/1]). -export([reduce/3, rereduce/3,validate_doc_update/5]). -export([render_doc_show/6, start_view_list/2, - render_list_head/4, render_list_row/3, render_list_tail/1]). + render_list_head/4, render_list_row/4, render_list_tail/1]). -export([start_filter/2, filter_doc/4, end_filter/1]). % -export([test/0]). @@ -199,11 +199,11 @@ render_list_head({_Lang, Pid}, Req, Db, Head) -> JsonReq = couch_httpd_external:json_req_obj(Req, Db), couch_os_process:prompt(Pid, [<<"list">>, Head, JsonReq]). -render_list_row({_Lang, Pid}, Db, {{Key, DocId}, Value}) -> - JsonRow = couch_httpd_view:view_row_obj(Db, {{Key, DocId}, Value}, false), +render_list_row({_Lang, Pid}, Db, {{Key, DocId}, Value}, IncludeDoc) -> + JsonRow = couch_httpd_view:view_row_obj(Db, {{Key, DocId}, Value}, IncludeDoc), couch_os_process:prompt(Pid, [<<"list_row">>, JsonRow]); -render_list_row({_Lang, Pid}, _, {Key, Value}) -> +render_list_row({_Lang, Pid}, _, {Key, Value}, _IncludeDoc) -> JsonRow = {[{key, Key}, {value, Value}]}, couch_os_process:prompt(Pid, [<<"list_row">>, JsonRow]). -- cgit v1.2.3