Last active
August 29, 2015 14:04
-
-
Save nolanlawson/15c9b9eeafd0a55a8c50 to your computer and use it in GitHub Desktop.
pouchdb "get then put" with promises
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// with promises | |
pouch.get('id').then(null, function (err) { | |
if (err.code === 404) { | |
// not found | |
return {}; // default doc | |
} | |
throw err; | |
}).then(function (doc) { | |
doc.value = 'some new value'; | |
return pouch.put(doc); | |
}, function (err) { | |
// handle any errors | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment