From 0a46c330072a3811d98a5c989d4c6486cff83df2 Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Fri, 23 Jan 2009 00:53:05 +0000 Subject: View list functions can stream views in any format. See list_views test for details. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@736876 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_query_servers.erl | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/couchdb/couch_query_servers.erl') diff --git a/src/couchdb/couch_query_servers.erl b/src/couchdb/couch_query_servers.erl index 8d473381..a6bb6e06 100644 --- a/src/couchdb/couch_query_servers.erl +++ b/src/couchdb/couch_query_servers.erl @@ -17,7 +17,8 @@ -export([init/1, terminate/2, handle_call/3, handle_cast/2, handle_info/2,code_change/3,stop/0]). -export([start_doc_map/2, map_docs/2, stop_doc_map/1]). --export([reduce/3, rereduce/3,validate_doc_update/5,render_doc_show/5]). +-export([reduce/3, rereduce/3,validate_doc_update/5]). +-export([render_doc_show/5,start_view_list/2,render_list_head/5, render_list_row/4, render_list_tail/3]). % -export([test/0]). -include("couch_db.hrl"). @@ -134,6 +135,29 @@ render_doc_show(Lang, ShowSrc, Doc, Req, Db) -> ok = ret_os_process(Lang, Pid) end. +start_view_list(Lang, ListSrc) -> + Pid = get_os_process(Lang), + true = couch_os_process:prompt(Pid, [<<"add_fun">>, ListSrc]), + {ok, {Lang, Pid}}. + +render_list_head({_Lang, Pid}, Req, Db, TotalRows, Offset) -> + Head = {[{<<"total_rows">>, TotalRows}, {<<"offset">>, Offset}]}, + JsonReq = couch_httpd_external:json_req_obj(Req, Db), + couch_os_process:prompt(Pid, [<<"list_begin">>, Head, JsonReq]). + +render_list_row({_Lang, Pid}, Req, Db, {{Key, DocId}, Value}) -> + JsonRow = couch_httpd_view:view_row_obj(Db, {{Key, DocId}, Value}, false), + JsonReq = couch_httpd_external:json_req_obj(Req, Db), + couch_os_process:prompt(Pid, [<<"list_row">>, JsonRow, JsonReq]). + +render_list_tail({Lang, Pid}, Req, Db) -> + JsonReq = couch_httpd_external:json_req_obj(Req, Db), + JsonResp = couch_os_process:prompt(Pid, [<<"list_tail">>, JsonReq]), + ok = ret_os_process(Lang, Pid), + JsonResp. + + + init([]) -> % read config and register for configuration changes -- cgit v1.2.3