glynnbird commented on a change in pull request #88: Add optional support for 
native promises
URL: https://github.com/apache/couchdb-nano/pull/88#discussion_r198052572
 
 

 ##########
 File path: README.md
 ##########
 @@ -147,19 +149,74 @@ You can also see your document in 
[futon](http://localhost:5984/_utils).
 
 ## Promises
 
-Although `nano` is written using the "callback" style, it is easy enough to 
switch to a "Promises" style, using the 
[Bluebird](https://www.npmjs.com/package/bluebird) library:
+By default, `nano` has a pure callback-style API where every operation takes a 
callback function with error and result arguments:
 
 ```js
-var Promise = require('bluebird');
-var mydb = require('nano')('http://localhost:5984/animaldb');
+const nano = require('nano')('http://localhost:5984');
+var db = nano.db.use('animals');
 
-// create Promise-compatible versions of all functions
-Promise.promisifyAll(mydb);
+db.get('rabbit', function(err, doc) {
+  if (err) {
+    console.error('An error occured!', err);
+    return;
+  }
+  console.log('Got document:', doc);
+});
+```
+
+However, `nano` also supports a promised-based API that can be enabled by 
passing `promise: true` on initialization. In this mode callbacks are still 
accepted, but if you omit the callback argument, a promise will be returned 
instead:
+
+```js
+const nano = require('nano')({
+  url: 'http://localhost:5984',
+  promise: true
+});
+
+var db = nano.db.use('animals');
+
+db.get('rabbit')
+  .then(function(err, doc) {
+    console.log('Got document:', doc);
+  })
+  .catch(function(err, doc) {
 
 Review comment:
   When a Promise rejects, the function signature is `function(err)` not 
`function(err, doc)`

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to