37 lines
645 B
Go
37 lines
645 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
|
|
}
|