Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolanlawson/15c9b9eeafd0a55a8c50 to your computer and use it in GitHub Desktop.
Save nolanlawson/15c9b9eeafd0a55a8c50 to your computer and use it in GitHub Desktop.
pouchdb "get then put" with promises
// 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