Merge pull request #323 from cttttt/patch-1
body should be optional in db.atomic(design, updater, id, [body], [callback])
diff --git a/README.md b/README.md
index 8ca9dd3..3bfbe57 100644
--- a/README.md
+++ b/README.md
@@ -31,6 +31,7 @@
- [nano.db.replicate(source, target, [opts], [callback])](#nanodbreplicatesource-target-opts-callback)
- [nano.db.changes(name, [params], [callback])](#nanodbchangesname-params-callback)
- [nano.db.follow(name, [params], [callback])](#nanodbfollowname-params-callback)
+ - [nano.db.info([callback])](#nanodbinfocallback)
- [nano.use(name)](#nanousename)
- [nano.request(opts, [callback])](#nanorequestopts-callback)
- [nano.config](#nanoconfig)
@@ -300,6 +301,16 @@
});
```
+### nano.db.info([callback])
+
+gets database information.
+
+nano.db.info(function(err, body) {
+ if (!err) {
+ console.log('got database info'', body);
+ }
+});
+
### nano.use(name)
creates a scope where you operate inside `name`.
@@ -411,7 +422,7 @@
The `insert` function can also be used with the method signature `db.insert(doc,[callback])`, where the `doc` contains the `_id` field e.g.
~~~ js
-var alice = cloudant.use('alice')
+var alice = nano.use('alice')
alice.insert({ _id: 'myid', crazy: true }, function(err, body) {
if (!err)
console.log(body)
@@ -421,7 +432,7 @@
and also used to update an existing document, by including the `_rev` token in the document being saved:
~~~ js
-var alice = cloudant.use('alice')
+var alice = nano.use('alice')
alice.insert({ _id: 'myid', _rev: '1-23202479633c2b380f79507a776743d5', crazy: false }, function(err, body) {
if (!err)
console.log(body)
diff --git a/examples/express.js b/examples/express.js
index 51dceac..b49ba1d 100644
--- a/examples/express.js
+++ b/examples/express.js
@@ -12,16 +12,19 @@
var express = require('express')
, db = require('nano')('http://localhost:5984/my_couch')
- , app = module.exports = express.createServer()
+ , app = module.exports = express()
;
-app.get('/', function(request,response) {
- db.get('foo', function (error, body, headers) {
- if(error) { return response.send(error.message, error['status-code']); }
- response.send(body, 200);
- });
- });
+app.get('/', function(req, res) {
+ db.get('foo', function (error, body, headers) {
+ if(error) {
+ res.status(error.statusCode);
+ return res.send(error.message);
+ }
+ res.status(200);
+ res.send(body);
+ });
});
app.listen(3333);
-console.log('server is running. check expressjs.org for more cool tricks');
+console.log('server is running. check expressjs.com for more cool tricks');
diff --git a/lib/nano.js b/lib/nano.js
index 797a8b5..81d12d7 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -60,7 +60,7 @@
return db;
}
}
-
+
function scrub(str) {
if (str) {
str = str.replace(/\/\/(.*)@/,"//XXXXXX:XXXXXX@");
@@ -393,12 +393,18 @@
// http://docs.couchdb.org/en/latest/api/document/common.html#delete--db-docid
function destroyDoc(docName, rev, callback) {
- return relax({
- db: dbName,
- doc: docName,
- method: 'DELETE',
- qs: {rev: rev}
- }, callback);
+ if(!docName) {
+ if(callback)
+ callback("Invalid doc id", null);
+ }
+ else {
+ return relax({
+ db: dbName,
+ doc: docName,
+ method: 'DELETE',
+ qs: {rev: rev}
+ }, callback);
+ }
}
// http://docs.couchdb.org/en/latest/api/document/common.html#get--db-docid
@@ -466,6 +472,7 @@
qs = {};
}
+ qs = qs || {};
qs['include_docs'] = true;
return relax({
diff --git a/tests/integration/document/destroy.js b/tests/integration/document/destroy.js
index 0d6bdf7..7e07448 100644
--- a/tests/integration/document/destroy.js
+++ b/tests/integration/document/destroy.js
@@ -29,6 +29,14 @@
});
});
+it('should not delete a db', function(assert) {
+ db.destroy(undefined, undefined, function(error, response) {
+ assert.equal(error, 'Invalid doc id', 'validated delete parameters');
+ assert.equal(response, null, 'ok!');
+ assert.end();
+ });
+});
+
it('should delete a document', function(assert) {
db.destroy('foobaz', rev, function(error, response) {
assert.equal(error, null, 'deleted foo');