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]
|
2023-11-17 10:06:56 +00:00
|
|
|
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
|
|
|
|
}
|