Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk-wasm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
xxdk-wasm
Commits
da42a9e6
Commit
da42a9e6
authored
2 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
added generic delete helper to utils indexeddb
parent
f201359d
No related branches found
No related tags found
4 merge requests
!60
Revert "Fail a test to be sure it works"
,
!39
first pass at adding dm package to indexedDb, split some shared code into utils
,
!36
project/DM
,
!32
Admin Commands
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
indexedDb/utils.go
+34
-0
34 additions, 0 deletions
indexedDb/utils.go
with
34 additions
and
0 deletions
indexedDb/utils.go
+
34
−
0
View file @
da42a9e6
...
@@ -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
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment