glynnbird commented on a change in pull request #102: Promise support for Nano
- Issue 98
URL: https://github.com/apache/couchdb-nano/pull/102#discussion_r204400155
##########
File path: README.md
##########
@@ -109,87 +139,80 @@ In `nano` the callback function receives always three
arguments:
JSON parsed body, binary for non JSON responses.
* `header` - The HTTP _response header_ from CouchDB, if no error.
+The documentation will now follow the *Promises* style.
-A simple but complete example using callbacks is:
-
-``` js
-var nano = require('nano')('http://localhost:5984');
-
-// clean up the database we created previously
-nano.db.destroy('alice', function() {
- // create a new database
- nano.db.create('alice', function() {
- // specify the database we are going to use
- var alice = nano.use('alice');
- // and insert a document in it
- alice.insert({ happy: true }, 'rabbit', function(err, body, header) {
- if (err) {
- console.log('[alice.insert] ', err.message);
- return;
- }
- console.log('you have inserted the rabbit.')
- console.log(body);
- });
- });
-});
+------------------
+
+
+A simple but complete example is:
+
+```js
+const nano = require('nano')('http://localhost:5984');
+let alice;
+
+nano.db.destory('alice').then((response) => {
+ return nano.db.create('alice')
+}).then((response) => {
+ alice = nano.use('alice')
+ return alice.insert({ happy: true }, 'rabbit')
+}).then((response) => {
+ console.log('you have inserted a document with an _id of rabbit')
+ console.log(response);
+})
+```
+
+or in the `async/await` style:
Review comment:
👍
----------------------------------------------------------------
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