Confirmed users
53
edits
No edit summary |
No edit summary |
||
Line 128: | Line 128: | ||
The revisionId is a UUID and it can be used to retrieve the delta between a particular revisionId and the current one. This operation is done using |Promise<DataStoreChanges> getChanges(DOMString revisionId);|. Note that the object DataStoreChanges contains only useful operations: for example, the ID of record that has been updated and removed only shows up in the |removedIds| array. | The revisionId is a UUID and it can be used to retrieve the delta between a particular revisionId and the current one. This operation is done using |Promise<DataStoreChanges> getChanges(DOMString revisionId);|. Note that the object DataStoreChanges contains only useful operations: for example, the ID of record that has been updated and removed only shows up in the |removedIds| array. | ||
== Examples == | |||
=== Basic operations === | |||
// Here we retrieve the list of DataStores called 'contacts'. | |||
navigator.getDataStores("contacts").then(function(stores) { | |||
dump("DataStores called 'contacts': " + stores.length + "\n"); | |||
if (!stores.length) return; | |||
dump("Current revisionID: " + stores[0].revisionId + "\n"); | |||
// Retrieve an object from the first DataStore. | |||
stores[0].get(42).then(function(obj) { | |||
// ... | |||
// Update an object | |||
obj.nick = 'baku'; | |||
stores[0].update(42, obj).then(function(id) { | |||
// id == 42 | |||
// ... | |||
}, function(error) { | |||
// something wrong happened. Error is a DOMError object. | |||
}); | |||
}); | |||
// Delete an object | |||
stores[0].remove(23).then(function(success) { | |||
if (success) { | |||
// The object has been deleted. | |||
} else { | |||
// Object 23 didn't exist. | |||
} | |||
}); | |||
// Storing a new object | |||
stores[0].add({ "nick": "baku", "email" : "a@b.c" }).then(function(id) { | |||
// ... | |||
}); | |||
}); | |||
=== Revisions === | |||
// Let's assume that I have a revisionId stored somewhere (IndexedDb? LocalStorage?) | |||
var revisionId = 'b66e9248-5990-4ac3-9f5d-3cdeb02b337f'; | |||
navigator.getDataStores('contacts').then(function(stores) { | |||
if (!stores.length) return; | |||
stores[0].getChanges(revisionId).then(function(delta) { | |||
// TODO | |||
}); | |||
}); | |||
== Issues == | == Issues == |