From 4b691efb97cbbe3b0150c59c25d97882260a4984 Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Fri, 13 Feb 2009 20:52:28 +0000 Subject: apply COUCHDB-252. Allow _list functions to signal that iteration of the view should cease. Thanks davisp. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@744240 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/couch_tests.js | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'share') diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index bc4e067a..0ffee4cd 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -2796,9 +2796,33 @@ db.createDb(); } }) }), - qsParams: stringFun(function(head, row, req, row_number) { + qsParams: stringFun(function(head, row, req, row_info) { if(head) return {body: req.query.foo}; else return {body: "\n"}; + }), + stopIter: stringFun(function(head, row, req, row_info) { + if(head) { + return {body: "head"}; + } else if(row) { + if(row_info.row_number > 2) return {stop: true}; + return {body: " " + row_info.row_number}; + } else { + return {body: " tail"}; + } + }), + stopIter2: stringFun(function(head, row, req, row_info) { + return respondWith(req, { + html: function() { + if(head) { + return "head"; + } else if(row) { + if(row_info.row_number > 2) return {stop: true}; + return " " + row_info.row_number; + } else { + return " tail"; + } + } + }); }) } }; @@ -2870,6 +2894,15 @@ db.createDb(); // now with extra qs params xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/qsParams/basicView?foo=blam"); T(xhr.responseText.match(/blam/)); + + + // aborting iteration + xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/stopIter/basicView"); + T(xhr.responseText.match(/^head 0 1 2 tail$/)); + xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/stopIter2/basicView"); + T(xhr.responseText.match(/^head 0 1 2 tail$/)); + + }, compact: function(debug) { -- cgit v1.2.3