Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

copy params into a new object

  • Loading branch information...
commit add3455bb9e83b01494374e43960b4c324cd2505 1 parent 5a6f081
@chesles chesles authored
Showing with 32 additions and 6 deletions.
  1. +6 −5 nano.js
  2. +26 −1 tests/design/query.js
View
11 nano.js
@@ -18,6 +18,7 @@ var request = require('request').defaults({ jar: false })
, fs = require('fs')
, qs = require('querystring')
, u = require('url')
+ , util = require('util')
, errs = require('errs')
, follow
, nano
@@ -105,7 +106,7 @@ module.exports = exports = nano = function database_module(cfg) {
}
var log = logging()
- , params = opts.params
+ , params = util._extend({}, opts.params)
, headers = { "content-type": "application/json"
, "accept" : "application/json"
}
@@ -186,14 +187,14 @@ module.exports = exports = nano = function database_module(cfg) {
}
// these need to be encoded
- if(!isEmpty(params)) {
+ if(!isEmpty(opts.params)) {
try {
['startkey', 'endkey', 'key', 'keys'].forEach(function (key) {
- if (key in params) {
- try { params[key] = JSON.stringify(params[key]); }
+ if (key in opts.params) {
+ try { params[key] = JSON.stringify(opts.params[key]); }
catch (err) {
return errs.handle(errs.merge(err,
- { "message": "bad params: " + key + " = " + params[key]
+ { "message": "bad params: " + key + " = " + opts.params[key]
, "scope" : "nano"
, "errid" : "encode_keys"
}), callback);
View
27 tests/design/query.js
@@ -48,6 +48,31 @@ specify("design_query:test", timeout, function (assert) {
});
});
+specify("design_query:reuse_params", timeout, function (assert) {
+ var opts = {
+ key: ["Derek","San Francisco"]
+ };
+ db.view('people','by_name_and_city', opts, function(error, view) {
+ assert.equal(error, undefined, "View didn't respond");
+ assert.equal(view.rows.length,1);
+ assert.equal(view.rows.length,1);
+ assert.equal(view.rows[0].id,'p_derek');
+ assert.equal(view.rows[0].key[0],'Derek');
+ assert.equal(view.rows[0].key[1],'San Francisco');
+ });
+ db.view('people','by_name_and_city', opts, function(error, view) {
+ assert.equal(error, undefined, "View didn't respond");
+ assert.equal(view.rows.length,1);
+ assert.equal(view.rows.length,1);
+ assert.equal(view.rows[0].id,'p_derek');
+ assert.equal(view.rows[0].key[0],'Derek');
+ assert.equal(view.rows[0].key[1],'San Francisco');
+ });
+ assert.ok(Array.isArray(opts.key));
+ assert.equal(opts.key[0],'Derek');
+ assert.equal(opts.key[1],'San Francisco');
+});
+
specify("design_query:teardown", timeout, function (assert) {
nano.db.destroy("design_query", function (err) {
assert.equal(err, undefined, "Failed to destroy database");
@@ -55,4 +80,4 @@ specify("design_query:teardown", timeout, function (assert) {
});
});
-specify.run(process.argv.slice(2));
+specify.run(process.argv.slice(2));
Please sign in to comment.
Something went wrong with that request. Please try again.