db

package
v0.0.0-...-f2e927d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLeaderboardNotFound         = errors.New("leaderboard not found")
	ErrLeaderboardInvalidFieldName = errors.New("invalid field name")
	ErrLeaderboardHasNoEntries     = errors.New("leaderboard has no entries")
	ErrEntryNotFound               = errors.New("entry not found")
	ErrEntryInvalidSortKey         = errors.New("invalid sort key")
)

Functions

This section is empty.

Types

type DB

type DB interface {
	// Leaderboard operations.
	CreateLeaderboard(name string, fieldNames []string, entries map[uuid.UUID]*Entry) *Leaderboard
	ReadLeaderboard(id uuid.UUID) *Leaderboard
	// Entry operations.
	CreateEntry(leaderboardId uuid.UUID, name string, fieldValues map[string]int) (*Entry, error)
	UpdateEntry(leaderboardId uuid.UUID, entryId uuid.UUID, fieldValues map[string]int) (*Entry, error)
	ReadEntries(leaderboardId uuid.UUID, sortKey, order string) ([]*Entry, error)
}

func NewMemDB

func NewMemDB() DB

type Entry

type Entry struct {
	ID                 uuid.UUID      `json:"id"`
	Name               string         `json:"name"`
	FieldNamesToValues map[string]int `json:"fieldNamesToValues"`
}

func NewEntry

func NewEntry(name string, fieldValues map[string]int) *Entry

type Leaderboard

type Leaderboard struct {
	ID         uuid.UUID            `json:"id"`
	Name       string               `json:"name"`
	FieldNames []string             `json:"fieldNames"`
	Entries    map[uuid.UUID]*Entry `json:"entries,omitempty"`
}

func NewLeaderboard

func NewLeaderboard(name string, fieldNames []string, entries map[uuid.UUID]*Entry) *Leaderboard

func (*Leaderboard) HasFieldName

func (l *Leaderboard) HasFieldName(name string) bool

type MemDB

type MemDB struct{}

func (*MemDB) CreateEntry

func (d *MemDB) CreateEntry(
	leaderboardId uuid.UUID,
	name string,
	fieldValues map[string]int,
) (*Entry, error)

func (*MemDB) CreateLeaderboard

func (d *MemDB) CreateLeaderboard(
	name string,
	fieldNames []string,
	entries map[uuid.UUID]*Entry,
) *Leaderboard

func (*MemDB) ReadEntries

func (d *MemDB) ReadEntries(leaderboardId uuid.UUID, sortKey, order string) ([]*Entry, error)

func (*MemDB) ReadLeaderboard

func (d *MemDB) ReadLeaderboard(id uuid.UUID) *Leaderboard

func (*MemDB) UpdateEntry

func (d *MemDB) UpdateEntry(
	leaderboardId uuid.UUID,
	entryId uuid.UUID,
	fieldValues map[string]int,
) (*Entry, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL