db

package
v1.3.10 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package db contains persistence functions to store and query data for the server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Datastore

type Datastore struct {
	// contains filtered or unexported fields
}

Datastore interface can be used to access and persist data

func NewDatastore

func NewDatastore(dataSourceName string, log *log.Logger, fs fs.ReadFileFS) (*Datastore, error)

NewDatastore creates a new sqlDatastore

func (Datastore) AddUser

func (ds Datastore) AddUser(username string, p Password) error

AddUser creates a user with the specified username and password

func (Datastore) ClearStat

func (ds Datastore) ClearStat(st SportType) error

ClearStat clears the stats for the active year

func (Datastore) GetFriends

func (ds Datastore) GetFriends(st SportType) ([]Friend, error)

GetFriends gets the friends for the active year for a SportType

func (Datastore) GetPlayerTypes

func (ds Datastore) GetPlayerTypes() (PlayerTypeMap, error)

GetPlayerTypes loads the PlayerTypes from the database

func (Datastore) GetPlayers

func (ds Datastore) GetPlayers(st SportType) ([]Player, error)

GetPlayers gets the players for the active year for a SportType

func (Datastore) GetSportTypes

func (ds Datastore) GetSportTypes() (SportTypeMap, error)

GetSportTypes returns the SportTypes from the database

func (Datastore) GetStat

func (ds Datastore) GetStat(st SportType) (*Stat, error)

GetStat gets the Stat for the active year, nil if there is not active stat

func (Datastore) GetUtcTime

func (Datastore) GetUtcTime() time.Time

GetUtcTime retrieves the current UTC time

func (Datastore) GetYears

func (ds Datastore) GetYears(st SportType) ([]Year, error)

GetYears gets years for a SportType

func (Datastore) IsCorrectUserPassword

func (ds Datastore) IsCorrectUserPassword(username string, p Password) (bool, error)

IsCorrectUserPassword determines whether the password for the user is correct

func (*Datastore) LimitPlayerTypes

func (ds *Datastore) LimitPlayerTypes(playerTypesCsv string) error

LimitPlayerTypes reduces the player types to those in the specified csv. Also limits the sport types to those for the specified player types. Note that this function mutates the supplied maps.

func (Datastore) PlayerTypes

func (ds Datastore) PlayerTypes() PlayerTypeMap

PlayerTypes implements the PlayerTypeGetter interface for Datastore

func (Datastore) SaveFriends

func (ds Datastore) SaveFriends(st SportType, futureFriends []Friend) error

SaveFriends saves the specified friends for the active year for a SportType

func (Datastore) SavePlayers

func (ds Datastore) SavePlayers(st SportType, futurePlayers []Player) error

SavePlayers saves the specified players for the active year for a SportType

func (Datastore) SaveYears

func (ds Datastore) SaveYears(st SportType, futureYears []Year) error

SaveYears saves the specified years and sets the active year for a SportType

func (Datastore) SetAdminPassword

func (ds Datastore) SetAdminPassword(p Password) error

SetAdminPassword sets the admin password If the admin user does not exist, it is created.

func (Datastore) SetStat

func (ds Datastore) SetStat(stat Stat) error

SetStat sets the etl timestamp and json for the year (which must be active)

func (Datastore) SetUserPassword

func (ds Datastore) SetUserPassword(username string, p Password) error

SetUserPassword gets the password for the specified user

func (Datastore) SportTypes

func (ds Datastore) SportTypes() SportTypeMap

SportTypes implements the SportTypeGetter interface for Datastore

type Friend

type Friend struct {
	ID           ID
	DisplayOrder int
	Name         string
}

Friend contains the name of the person in the pool.

type ID

type ID string

ID is used to identify an item in the database or a relation to another noun's id

func (*ID) Scan

func (id *ID) Scan(src interface{}) error

type Password

type Password string

Password is a string that can be validated

type Player

type Player struct {
	ID           ID
	PlayerType   PlayerType
	SourceID     SourceID
	FriendID     ID
	DisplayOrder int
}

Player maps a player (of a a specific PlayerType) to a Friend.

type PlayerType

type PlayerType int

PlayerType is an enumeration of types of players

const (
	PlayerTypeMlbTeam    PlayerType = 1
	PlayerTypeMlbHitter  PlayerType = 2
	PlayerTypeMlbPitcher PlayerType = 3
	PlayerTypeNflTeam    PlayerType = 4
	PlayerTypeNflQB      PlayerType = 5
	PlayerTypeNflMisc    PlayerType = 6
)

The expected PlayerTypes

type PlayerTypeInfo

type PlayerTypeInfo struct {
	SportType    SportType
	Name         string
	Description  string
	ScoreType    string
	DisplayOrder int
}

PlayerTypeInfo contains supplementary information about a PlayerType

type PlayerTypeMap

type PlayerTypeMap map[PlayerType]PlayerTypeInfo

PlayerTypeMap contains information about multiple PlayerTypes and their PlayerTypeInfos

type SourceID

type SourceID int

SourceID is the id used to retrieve information about the player from external sources

type SportType

type SportType int

SportType is an enumeration of types of sports

const (
	SportTypeMlb SportType = 1
	SportTypeNfl SportType = 2
)

The expected SportTypes

type SportTypeInfo

type SportTypeInfo struct {
	Name         string
	URL          string
	DisplayOrder int
}

SportTypeInfo contains supplementary information about a SportType

type SportTypeMap

type SportTypeMap map[SportType]SportTypeInfo

SportTypeMap contains information about multiple SportTypes and their SportTypeInfos

type Stat

type Stat struct {
	SportType    SportType
	Year         int
	EtlTimestamp *time.Time
	EtlJSON      string
}

Stat is a wrapper for EtlJSON It is for a particular year and SportType. It has an etl timestamp.

type Year

type Year struct {
	Value  int
	Active bool
}

Year contains a year that has been set for stats and whether it is active

Jump to

Keyboard shortcuts

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