Skip to content
Snippets Groups Projects
Commit da42a9e6 authored by Jake Taylor's avatar Jake Taylor
Browse files

added generic delete helper to utils indexeddb

parent f201359d
No related branches found
No related tags found
4 merge requests!60Revert "Fail a test to be sure it works",!39first pass at adding dm package to indexedDb, split some shared code into utils,!36project/DM,!32Admin Commands
...@@ -147,6 +147,40 @@ func Put(db *idb.Database, objectStoreName string, value js.Value) (*idb.Request ...@@ -147,6 +147,40 @@ func Put(db *idb.Database, objectStoreName string, value js.Value) (*idb.Request
return request, nil return request, nil
} }
// Delete is a generic helper for removing values from the given [idb.ObjectStore].
func Delete(db *idb.Database, objectStoreName string, key js.Value) error {
parentErr := errors.Errorf("failed to Delete %s/%s", objectStoreName, key)
// Prepare the Transaction
txn, err := db.Transaction(idb.TransactionReadOnly, objectStoreName)
if err != nil {
return errors.WithMessagef(parentErr,
"Unable to create Transaction: %+v", err)
}
store, err := txn.ObjectStore(objectStoreName)
if err != nil {
return errors.WithMessagef(parentErr,
"Unable to get ObjectStore: %+v", err)
}
// Perform the operation
deleteRequest, err := store.Delete(key)
if err != nil {
return errors.WithMessagef(parentErr,
"Unable to Get from ObjectStore: %+v", err)
}
// Wait for the operation to return
ctx, cancel := NewContext()
err = deleteRequest.Await(ctx)
cancel()
if err != nil {
return errors.WithMessagef(parentErr,
"Unable to delete from ObjectStore: %+v", err)
}
return nil
}
// Dump returns the given [idb.ObjectStore] contents to string slice for // Dump returns the given [idb.ObjectStore] contents to string slice for
// testing and debugging purposes. // testing and debugging purposes.
func Dump(db *idb.Database, objectStoreName string) ([]string, error) { func Dump(db *idb.Database, objectStoreName string) ([]string, error) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment