Created
April 1, 2017 08:53
-
-
Save karlwestin/81fa111781350e2f77010f10c9e94cc1 to your computer and use it in GitHub Desktop.
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
public save() { | |
let db = this.get_db(); | |
let data = this.get_data(); | |
let t = this; | |
console.log('Save:' + this._id); | |
db.get(this._id, {conflicts: false}) | |
.catch(function (err) { | |
if (err.status === 404) { | |
return {}; // you can just return an empty map if docs not found | |
} | |
throw err; // re-throw any other err to propagate | |
}) | |
.then(function (doc) { | |
// You probably don't need to handle 409s, unless you're trying to do multiple saves at the same time | |
data._rev = doc._rev; | |
return db.put(data); // put updated doc, will create new revision | |
}) | |
.then(saveSuccessful) | |
.catch(function (err) { | |
console.log(err); | |
}); | |
}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment