From cf69d22a07e9c8687dda93c830f5ff01f99be829 Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Sun, 5 Oct 2008 16:00:15 +0000 Subject: added multi-key requests to _view, _temp_view, and _all_docs (with help from davisp) git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@701814 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/couch.js | 29 +++++-- share/www/script/couch_tests.js | 181 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 205 insertions(+), 5 deletions(-) (limited to 'share') diff --git a/share/www/script/couch.js b/share/www/script/couch.js index cf26bb2e..87bba88a 100644 --- a/share/www/script/couch.js +++ b/share/www/script/couch.js @@ -112,8 +112,11 @@ function CouchDB(name) { } // Applies the map function to the contents of database and returns the results. - this.query = function(mapFun, reduceFun, options) { + this.query = function(mapFun, reduceFun, options, keys) { var body = {language: "javascript"}; + if(keys) { + body.keys = keys ; + } if (typeof(mapFun) != "string") mapFun = mapFun.toSource ? mapFun.toSource() : "(" + mapFun.toString() + ")"; body.map = mapFun; @@ -132,8 +135,16 @@ function CouchDB(name) { return result; } - this.view = function(viewname, options) { - var req = request("GET", this.uri + "_view/" + viewname + encodeOptions(options)); + this.view = function(viewname, options, keys) { + var req = null ; + if(!keys) { + req = request("GET", this.uri + "_view/" + viewname + encodeOptions(options)); + } else { + req = request("POST", this.uri + "_view/" + viewname + encodeOptions(options), { + headers: {"Content-Type": "application/json"}, + body: JSON.stringify({keys:keys}) + }); + } if (req.status == 404) return null; var result = JSON.parse(req.responseText); @@ -151,8 +162,16 @@ function CouchDB(name) { return result; } - this.allDocs = function(options) { - var req = request("GET", this.uri + "_all_docs" + encodeOptions(options)); + this.allDocs = function(options,keys) { + var req = null; + if(!keys) { + req = request("GET", this.uri + "_all_docs" + encodeOptions(options)); + } else { + req = request("POST", this.uri + "_all_docs" + encodeOptions(options), { + headers: {"Content-Type": "application/json"}, + body: JSON.stringify({keys:keys}) + }); + } var result = JSON.parse(req.responseText); if (req.status != 200) throw result; diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index 3abd570e..b2b0bbb1 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -1089,6 +1089,187 @@ var tests = { T(results.total_rows == 0); }, + view_multi_key_all_docs: function(debug) { + var db = new CouchDB("test_suite_db"); + db.deleteDb(); + db.createDb(); + if (debug) debugger; + + var docs = makeDocs(0, 100); + T(db.bulkSave(docs).ok); + + var keys = ["10","15","30","37","50"]; + var rows = db.allDocs({},keys).rows; + T(rows.length == keys.length); + for(var i=0; i