-
-
Notifications
You must be signed in to change notification settings - Fork 641
WriteableCollection.delete()
Deletes all objects in the query.
collection.delete()
Promise where result is an array of arrays [key, value] of all deleted objects. If any object fails to delete, entire operation will fail and transaction aborted unless the returned Promise is catched.
If not catching returned Promise, any error will abort transaction. This also applies for direct access without a transaction() block, since the operation still use a transaction internally. This means that if just a single object fails to be deleted, all deletions will be aborted.
If you catch the returned Promise, you recieve an Error object containing the following properties:
failures | Array of Error objects of all errors that have occurred |
failedRecords | Array of failed records. Each record is an array of [key, object] |
deletedRecords | Array of successfully deleted records. Each record is an array of [key, object] |
If you catch the returned Promise, the transaction will NOT be aborted.
If you do not catch the returned Promise, the transaction will be aborted.
If you want to log the error but still abort the transaction, you must encapsulate the operation in a transaction() block and catch the transaction instead.
db.orders.where("state").anyOf("finished", "discarded").or("date").below("2014-02-01").delete()
.then(function (deletedOrders) {
console.log( JSON.stringify(deletedOrders) ):
});
This method is equivalent to the following:
var deletedRecords = [];
collection.each(function (item, cursor) {
deletedRecords.push([cursor.key, cursor.value]);
cursor.delete();
}).then (function () {
return deletedRecords;
});
Dexie.js - minimalistic and bullet proof indexedDB library