jldb/mdb/db-userdata_test.go
J. David Lee ba1990e379 v2 (#2)
Co-authored-by: jdl <jdl@desktop>
Reviewed-on: #2
2023-11-17 10:06:56 +00:00

37 lines
646 B
Go

package mdb
import (
"cmp"
"strings"
)
type UserDataItem struct {
ID uint64
UserID uint64
Name string
Data string
}
type UserData struct {
*Collection[UserDataItem]
ByName *Index[UserDataItem] // Unique index on (Token).
}
func NewUserDataCollection(db *Database) UserData {
userData := UserData{}
userData.Collection = NewCollection[UserDataItem](db, "UserData", nil)
userData.ByName = NewUniqueIndex(
userData.Collection,
"ByName",
func(lhs, rhs *UserDataItem) int {
if x := cmp.Compare(lhs.UserID, rhs.UserID); x != 0 {
return x
}
return strings.Compare(lhs.Name, rhs.Name)
})
return userData
}