You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by gl...@apache.org on 2019/05/02 14:07:27 UTC
[couchdb-nano] branch master updated: Support database create
params. (#158)
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
The following commit(s) were added to refs/heads/master by this push:
new 128a851 Support database create params. (#158)
128a851 is described below
commit 128a851b46e522c1f311ca63b1bf1871c61881f8
Author: Sam Smith <sa...@linux.vnet.ibm.com>
AuthorDate: Thu May 2 15:07:23 2019 +0100
Support database create params. (#158)
---
lib/nano.d.ts | 8 +++++++-
lib/nano.js | 5 +++--
tests/fixtures/database/create-and-destroy.json | 10 ++++++++++
tests/integration/database/create-and-destroy.js | 18 ++++++++++++++++++
4 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/lib/nano.d.ts b/lib/nano.d.ts
index e570772..77ddd0a 100644
--- a/lib/nano.d.ts
+++ b/lib/nano.d.ts
@@ -52,9 +52,15 @@ declare namespace nano {
uuids: string[]
}
+ interface DatabaseCreateParams {
+ n?: number;
+ partitioned?: boolean;
+ q?: number;
+ }
+
interface DatabaseScope {
// http://docs.couchdb.org/en/latest/api/database/common.html#put--db
- create(name: string, callback?: Callback<DatabaseCreateResponse>): Promise<DatabaseCreateResponse>;
+ create(name: string, params?: DatabaseCreateParams, callback?: Callback<DatabaseCreateResponse>): Promise<DatabaseCreateResponse>;
// http://docs.couchdb.org/en/latest/api/database/common.html#get--db
get(name: string, callback?: Callback<DatabaseGetResponse>): Promise<DatabaseGetResponse>;
// http://docs.couchdb.org/en/latest/api/database/common.html#delete--db
diff --git a/lib/nano.js b/lib/nano.js
index d13b02d..1d5801b 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -331,8 +331,9 @@ module.exports = exports = function dbScope (cfg) {
}
// http://docs.couchdb.org/en/latest/api/database/common.html#put--db
- function createDb (dbName, callback) {
- return relax({db: dbName, method: 'PUT'}, callback)
+ function createDb (dbName, qs0, callback0) {
+ const {opts, callback} = getCallback(qs0, callback0)
+ return relax({db: dbName, method: 'PUT', qs: opts}, callback)
}
// http://docs.couchdb.org/en/latest/api/database/common.html#delete--db
diff --git a/tests/fixtures/database/create-and-destroy.json b/tests/fixtures/database/create-and-destroy.json
index 5087f8a..fa96f3a 100644
--- a/tests/fixtures/database/create-and-destroy.json
+++ b/tests/fixtures/database/create-and-destroy.json
@@ -10,6 +10,16 @@
, "response" : "{ \"ok\": true }"
}
, { "method" : "put"
+ , "path" : "/newdb1"
+ , "status" : 201
+ , "response" : "{ \"ok\": true }"
+ }
+, { "method" : "put"
+ , "path" : "/newdb2?q=1&n=3"
+ , "status" : 201
+ , "response" : "{ \"ok\": true }"
+ }
+, { "method" : "put"
, "path" : "/with%2Fslash"
, "status" : 201
, "response" : "{ \"ok\": true }"
diff --git a/tests/integration/database/create-and-destroy.js b/tests/integration/database/create-and-destroy.js
index 16817db..031e5b3 100644
--- a/tests/integration/database/create-and-destroy.js
+++ b/tests/integration/database/create-and-destroy.js
@@ -26,6 +26,24 @@ it('should be able to create `az09_$()+-/` database', function (assert) {
})
})
+it('should be able to create a database without query parameters', function (assert) {
+ nano.db.create('newdb1').then(function (body) {
+ assert.ok(body.ok)
+ assert.end()
+ }).catch(function () {
+ assert.ok(false, 'Promise is rejected')
+ })
+})
+
+it('should be able to create a database with query parameters', function (assert) {
+ nano.db.create('newdb2', { q: 1, n: 3 }).then(function (body) {
+ assert.ok(body.ok)
+ assert.end()
+ }).catch(function () {
+ assert.ok(false, 'Promise is rejected')
+ })
+})
+
it('should be able to use config from a nano object to create a db',
function (assert) {
const config = helpers.Nano(