You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/07/24 15:37:07 UTC

[GitHub] janl closed pull request #80: Multi view queries tests

janl closed pull request #80: Multi view queries tests
URL: https://github.com/apache/couchdb-nano/pull/80
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/lib/nano.js b/lib/nano.js
index fd4bf92..33501e6 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -591,6 +591,16 @@ module.exports = exports = nano = function dbScope(cfg) {
           qs: qs1,
           body: body
         }, callback);
+      } else if (qs && qs.queries) {
+        body = {queries: qs.queries};
+        delete qs.queries;
+        return relax({
+          db: dbName,
+          path: viewPath,
+          method: 'POST',
+          qs: qs,
+          body: body
+        }, callback);
       } else {
         var req = {
           db: dbName,
diff --git a/tests/fixtures/design/query.json b/tests/fixtures/design/query.json
index 956707d..2a969c4 100644
--- a/tests/fixtures/design/query.json
+++ b/tests/fixtures/design/query.json
@@ -37,6 +37,11 @@
 , { "path"     : "/design_query/_design/people/_view/by_name_and_city?key=%5B%22Derek%22%2C%22San%20Francisco%22%5D"
   , "response" : "{\"total_rows\":3,\"offset\":0,\"rows\":[\r\n{\"id\":\"p_derek\",\"key\":[\"Derek\",\"San Francisco\"],\"value\":\"p_derek\"}\r\n]}\n"
   }
+, { "method"   : "post"
+  , "path"     : "/design_query/_design/people/_view/by_name_and_city"
+  , "body"     : "{\"queries\":[{\"keys\":[[\"Derek\",\"San Francisco\"],[\"Nuno\",\"London\"]]},{\"skip\":2,\"limit\":1}]}"
+  , "response" : "{\"results\":[{\"total_rows\":3,\"offset\":0,\"rows\":[{\"id\":\"p_derek\",\"key\":[\"Derek\",\"San Francisco\"],\"value\":\"p_derek\"},{\"id\":\"p_nuno\",\"key\":[\"Nuno\",\"London\"],\"value\":\"p_nuno\"}]},{\"total_rows\":3,\"offset\":2,\"rows\":[{\"id\":\"p_randall\",\"key\":[\"Randall\",\"San Francisco\"],\"value\":\"p_randall\"}]}]}"
+  }
 , { "method"   : "delete"
   , "path"     : "/design_query"
   , "status"   : 200
diff --git a/tests/integration/design/query.js b/tests/integration/design/query.js
index c2b2022..f616320 100644
--- a/tests/integration/design/query.js
+++ b/tests/integration/design/query.js
@@ -39,3 +39,36 @@ it('should have no cloning issues when doing queries', function(assert) {
     assert.end();
   });
 });
+
+var multipleQueryOpts = {
+  queries: [
+    {
+      keys: [
+        ['Derek','San Francisco'],
+        ['Nuno','London']
+      ]
+    }, 
+    {
+      skip: 2,
+      limit: 1
+    }
+  ]
+}
+
+var expectedResults = 
+  [
+    {total_rows:3,offset:0,rows:[{id:"p_derek",key:["Derek","San Francisco"],value:"p_derek"},{id:"p_nuno",key:["Nuno","London"],value:"p_nuno"}]},
+    {total_rows:3,offset:2,rows:[{id:"p_randall",key:["Randall","San Francisco"],value:"p_randall"}]}
+  ]
+
+
+it('should support multiple view queries', function(assert) {
+  db.view('people','by_name_and_city', multipleQueryOpts, function(error, response) {
+    assert.equal(error, null, 'no errors');
+    assert.ok(response.results, 'should return query results')
+    assert.ok(Array.isArray(response.results), 'query results should be array');
+    assert.equal(response.results.length, 2, 'should return results to both queries')
+    assert.deepEqual(response.results, expectedResults, 'should be expected query results')
+    assert.end()
+  });
+});
diff --git a/tests/unit/design/view.js b/tests/unit/design/view.js
index df441e3..ba4b4f7 100644
--- a/tests/unit/design/view.js
+++ b/tests/unit/design/view.js
@@ -32,3 +32,19 @@ viewDesign('alice', 'by_id', {
   },
   uri: '/mock/_design/alice/_view/by_id'
 });
+
+viewDesign('alice', 'by_id', {
+  queries: [{ keys: ['foobar', 'barfoo']}, { limit: 3, skip: 2 }],
+  include_docs: true
+}, {
+  body: '{"queries":[{"keys":["foobar","barfoo"]},{"limit":3,"skip":2}]}',
+  headers: {
+    accept: 'application/json',
+    'content-type': 'application/json'
+  },
+  method: 'POST',
+  qs: {
+    'include_docs': true
+  },
+  uri: '/mock/_design/alice/_view/by_id'
+});
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services