From 9e53f467f89bc3942f8795f6d07f61d3f5115f88 Mon Sep 17 00:00:00 2001 From: Paul Joseph Davis Date: Wed, 10 Nov 2010 19:44:05 +0000 Subject: Support the keys parameter in GET requests. You can now request a list of keys in the query string using a query string like: ?keys=["foo", "bar"] Your query string obviously needs to be properly escaped. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1033676 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/couch.js | 2 +- share/www/script/test/list_views.js | 10 +++ share/www/script/test/view_multi_key_all_docs.js | 37 +++++++++++ share/www/script/test/view_multi_key_design.js | 78 ++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 1 deletion(-) (limited to 'share/www') diff --git a/share/www/script/couch.js b/share/www/script/couch.js index 913f58fb..bcc19652 100644 --- a/share/www/script/couch.js +++ b/share/www/script/couch.js @@ -272,7 +272,7 @@ function CouchDB(name, httpHeaders) { for (var name in options) { if (!options.hasOwnProperty(name)) { continue; }; var value = options[name]; - if (name == "key" || name == "startkey" || name == "endkey") { + if (name == "key" || name == "keys" || name == "startkey" || name == "endkey") { value = toJSON(value); } buf.push(encodeURIComponent(name) + "=" + encodeURIComponent(value)); diff --git a/share/www/script/test/list_views.js b/share/www/script/test/list_views.js index 8578622a..e98a212e 100644 --- a/share/www/script/test/list_views.js +++ b/share/www/script/test/list_views.js @@ -327,6 +327,16 @@ couchTests.list_views = function(debug) { T(/FirstKey: 2/.test(xhr.responseText)); T(/LastKey: 7/.test(xhr.responseText)); + // multi-key fetch with GET + var xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/simpleForm/basicView" + + "?keys=[2,4,5,7]"); + + T(xhr.status == 200, "multi key"); + T(!(/Key: 1 /.test(xhr.responseText))); + T(/Key: 2/.test(xhr.responseText)); + T(/FirstKey: 2/.test(xhr.responseText)); + T(/LastKey: 7/.test(xhr.responseText)); + // no multi-key fetch allowed when group=false xhr = CouchDB.request("POST", "/test_suite_db/_design/lists/_list/simpleForm/withReduce?group=false", { body: '{"keys":[2,4,5,7]}' diff --git a/share/www/script/test/view_multi_key_all_docs.js b/share/www/script/test/view_multi_key_all_docs.js index 62e49665..1113be4d 100644 --- a/share/www/script/test/view_multi_key_all_docs.js +++ b/share/www/script/test/view_multi_key_all_docs.js @@ -25,24 +25,52 @@ couchTests.view_multi_key_all_docs = function(debug) { for(var i=0; i