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
c8265900
Commit
c8265900
authored
2 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
added basic model.go
parent
06ad0e9c
No related branches found
No related tags found
2 merge requests
!60
Revert "Fail a test to be sure it works"
,
!4
Xx 4114/index db
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
indexedDb/init.go
+9
-5
9 additions, 5 deletions
indexedDb/init.go
indexedDb/model.go
+65
-0
65 additions, 0 deletions
indexedDb/model.go
with
74 additions
and
5 deletions
indexedDb/init.go
+
9
−
5
View file @
c8265900
...
@@ -17,16 +17,19 @@ import (
...
@@ -17,16 +17,19 @@ import (
"syscall/js"
"syscall/js"
"gitlab.com/elixxir/client/channels"
"gitlab.com/elixxir/client/channels"
"gitlab.com/xx_network/primitives/id"
)
)
// currentVersion of the IndexDb runtime. Used for migration purposes.
const
(
const
currentVersion
uint
=
1
// databaseSuffix to be appended to the name of the database
databaseSuffix
=
"_messenger"
// currentVersion of the IndexDb runtime. Used for migration purposes.
currentVersion
uint
=
1
)
// NewWasmEventModel returns a [channels.EventModel] backed by a wasmModel
// NewWasmEventModel returns a [channels.EventModel] backed by a wasmModel
func
NewWasmEventModel
(
receptionId
*
id
.
ID
)
(
channels
.
EventModel
,
error
)
{
func
NewWasmEventModel
(
username
string
)
(
channels
.
EventModel
,
error
)
{
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
databaseName
:=
receptionId
.
String
()
databaseName
:=
username
+
databaseSuffix
// Attempt to open database object
// Attempt to open database object
openRequest
,
_
:=
idb
.
Global
()
.
Open
(
ctx
,
databaseName
,
currentVersion
,
openRequest
,
_
:=
idb
.
Global
()
.
Open
(
ctx
,
databaseName
,
currentVersion
,
...
@@ -47,6 +50,7 @@ func NewWasmEventModel(receptionId *id.ID) (channels.EventModel, error) {
...
@@ -47,6 +50,7 @@ func NewWasmEventModel(receptionId *id.ID) (channels.EventModel, error) {
return
errors
.
Errorf
(
"Invalid version upgrade path: v%d -> v%d"
,
return
errors
.
Errorf
(
"Invalid version upgrade path: v%d -> v%d"
,
oldVersion
,
newVersion
)
oldVersion
,
newVersion
)
})
})
// Wait for database open to finish
// Wait for database open to finish
db
,
err
:=
openRequest
.
Await
(
ctx
)
db
,
err
:=
openRequest
.
Await
(
ctx
)
...
...
This diff is collapsed.
Click to expand it.
indexedDb/model.go
0 → 100644
+
65
−
0
View file @
c8265900
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2022 Privategrity Corporation /
// /
// All rights reserved. /
////////////////////////////////////////////////////////////////////////////////
//go:build js && wasm
// +build js,wasm
package
indexedDb
import
(
"time"
)
const
(
// Text representation of primary key value (keyPath).
pkeyName
=
"id"
// Text representation of the names of the various [idb.ObjectStore].
messageStoreName
=
"messages"
userStoreName
=
"users"
channelsStoreName
=
"channels"
// Message index names.
messageStoreChannelIndex
=
"channel_id_index"
messageStoreParentIndex
=
"parent_message_id_index"
messageStoreTimestampIndex
=
"timestamp_index"
messageStorePinnedIndex
=
"pinned_index"
// Message keyPath names (must match json struct tags).
messageStoreChannel
=
"channel_id"
messageStoreParent
=
"parent_message_id"
messageStoreTimestamp
=
"timestamp"
messageStorePinned
=
"pinned"
)
// Message defines the IndexedDb representation of a single Message.
// A Message belongs to one User (Sender).
// A Message belongs to one Channel.
// A Message may belong to one Message (Parent).
type
Message
struct
{
Id
[]
byte
`json:"id"`
// Matches pkeyName
SenderId
[]
byte
`json:"sender_id"`
ChannelId
[]
byte
`json:"channel_id"`
// Index
ParentMessageId
[]
byte
`json:"parent_message_id"`
// Index
Timestamp
time
.
Time
`json:"timestamp"`
// Index
Hidden
bool
`json:"hidden"`
Pinned
bool
`json:"pinned"`
// Index
}
// User defines the IndexedDb representation of a single User.
// A User sends many Message.
type
User
struct
{
Id
[]
byte
`json:"id"`
// Matches pkeyName
Username
string
`json:"username"`
}
// Channel defines the IndexedDb representation of a single Channel
// A Channel has many Message.
type
Channel
struct
{
Id
[]
byte
`json:"id"`
// Matches pkeyName
Name
string
`json:"name"`
Description
string
`json:"description"`
}
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