Skip to content

Instantly share code, notes, and snippets.

@glynrob
Created February 24, 2013 21:10
Show Gist options
  • Save glynrob/5025634 to your computer and use it in GitHub Desktop.
Save glynrob/5025634 to your computer and use it in GitHub Desktop.
Indexed DB delete row
function deleteRow(key) {
key = Number(key); // set as number - required to work
store = getObjectStore(DB_TABLE_NAME, 'readwrite'); // get the object store allowing read and write
var req = store.get(key); // get row from table
req.onsuccess = function(evt) { // success - able to get the row from the table
var record = evt.target.result;
if (typeof record == 'undefined') { // row is empty
displayActionFailure("No record found");
return;
}
req = store.delete(key); // delete row
req.onsuccess = function(evt) { // success - display table columns
displayRows(store);
};
req.onerror = function (evt) { // fail - display error
console.error("deleteRow:", evt.target.errorCode);
};
};
req.onerror = function (evt) { // fail - could not select row from key
console.error("deleteRow:", evt.target.errorCode);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment