-
-
Notifications
You must be signed in to change notification settings - Fork 677
WriteableTable.update()
Victor Lourng edited this page Apr 3, 2015
·
9 revisions
Updates existing object in the object store with given changes
table.update(key, changes)
key | Primary key |
changes | Object containing the key paths to each property you want to change. |
Promise with value 1 (= key was found and object updated) or 0 (key was not found and nothing was updated)
Similar to SQL UPDATE. The difference between update() and put() is that update() will only apply given changes to the object while put() will replace the entire object. Another difference is that in case key is not found, put() would create a new object while update() wont change anything. The returned Promise will NOT fail if key was not found but resolve with value 0 instead of 1.
Equivalent to ´WriteableTable.where(":id").equals(key).modify(changes);´
db.friends.update(2, {name: "Number 2"}).then(function (updated) {
if (updated)
console.log ("Friend number 2 was renamed to "Number 2");
else
console.log ("Nothing was updated - there were no friend with primary key: 2");
});
Dexie.js - minimalistic and bullet proof indexedDB library