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
a3ecc8c7
Commit
a3ecc8c7
authored
2 years ago
by
Jono Wenger
Browse files
Options
Downloads
Patches
Plain Diff
Add list to local storage that tracks indexedDb database names
parent
6938b69d
No related branches found
No related tags found
1 merge request
!18
XX-4272 / Purge
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
indexedDb/init.go
+8
-0
8 additions, 0 deletions
indexedDb/init.go
utils/indexedDbList.go
+53
-0
53 additions, 0 deletions
utils/indexedDbList.go
utils/indexedDbList_test.go
+38
-0
38 additions, 0 deletions
utils/indexedDbList_test.go
with
99 additions
and
0 deletions
indexedDb/init.go
+
8
−
0
View file @
a3ecc8c7
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
package
indexedDb
package
indexedDb
import
(
import
(
"gitlab.com/elixxir/xxdk-wasm/utils"
"syscall/js"
"syscall/js"
"github.com/hack-pad/go-indexeddb/idb"
"github.com/hack-pad/go-indexeddb/idb"
...
@@ -143,5 +144,12 @@ func v1Upgrade(db *idb.Database) error {
...
@@ -143,5 +144,12 @@ func v1Upgrade(db *idb.Database) error {
return
err
return
err
}
}
// Get the database name and save it to storage
if
databaseName
,
err
:=
db
.
Name
();
err
!=
nil
{
return
err
}
else
if
err
=
utils
.
StoreIndexedDb
(
databaseName
);
err
!=
nil
{
return
err
}
return
nil
return
nil
}
}
This diff is collapsed.
Click to expand it.
utils/indexedDbList.go
0 → 100644
+
53
−
0
View file @
a3ecc8c7
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2022 xx foundation //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file. //
////////////////////////////////////////////////////////////////////////////////
//go:build js && wasm
package
utils
import
(
"encoding/json"
"github.com/pkg/errors"
"os"
)
const
indexedDbListKey
=
"xxDkWasmIndexedDbList"
// GetIndexedDbList returns the list of stored indexedDb databases.
func
GetIndexedDbList
()
([]
string
,
error
)
{
var
list
[]
string
listBytes
,
err
:=
GetLocalStorage
()
.
GetItem
(
indexedDbListKey
)
if
err
!=
nil
&&
!
errors
.
Is
(
err
,
os
.
ErrNotExist
)
{
return
nil
,
err
}
else
if
err
==
nil
{
err
=
json
.
Unmarshal
(
listBytes
,
&
list
)
if
err
!=
nil
{
return
nil
,
err
}
}
return
list
,
nil
}
// StoreIndexedDb saved the indexedDb database name to storage.
func
StoreIndexedDb
(
databaseName
string
)
error
{
list
,
err
:=
GetIndexedDbList
()
if
err
!=
nil
{
return
err
}
list
=
append
(
list
,
databaseName
)
listBytes
,
err
:=
json
.
Marshal
(
list
)
if
err
!=
nil
{
return
err
}
GetLocalStorage
()
.
SetItem
(
indexedDbListKey
,
listBytes
)
return
nil
}
This diff is collapsed.
Click to expand it.
utils/indexedDbList_test.go
0 → 100644
+
38
−
0
View file @
a3ecc8c7
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2022 xx foundation //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file. //
////////////////////////////////////////////////////////////////////////////////
//go:build js && wasm
package
utils
import
(
"reflect"
"testing"
)
// Tests that three indexedDb database names stored with StoreIndexedDb are
// retrieved with GetIndexedDbList.
func
TestStoreIndexedDb_GetIndexedDbList
(
t
*
testing
.
T
)
{
expected
:=
[]
string
{
"db1"
,
"db2"
,
"db3"
}
for
_
,
name
:=
range
expected
{
err
:=
StoreIndexedDb
(
name
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed to store database name %q: %+v"
,
name
,
err
)
}
}
list
,
err
:=
GetIndexedDbList
()
if
err
!=
nil
{
t
.
Errorf
(
"Failed to get database list: %+v"
,
err
)
}
if
!
reflect
.
DeepEqual
(
expected
,
list
)
{
t
.
Errorf
(
"Did not get expected list.
\n
expected: %s
\n
received: %s"
,
expected
,
list
)
}
}
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