jldb/mdb/db-userdata_test.go

37 lines
646 B
Go
Raw Normal View History

2023-10-13 09:43:27 +00:00
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).
2023-10-13 09:43:27 +00:00
}
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
}