database

package
v0.0.0-...-843b749 Latest Latest
Warning

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

Go to latest
Published: May 21, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package database provides an interface through which the application can interact with a database.

Package database provides an interface through which the application can interact with a database.

Package database provides an interface through which the application can interact with a database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMatch

func CreateMatch(client1DatabaseID uint64, client2DatabaseID uint64) (matchID uint64, err error)

CreateMatch creates a match with the two clients specified, and returns the match id.

func GetClientNameAndAvatar

func GetClientNameAndAvatar(databaseID uint64) (displayname string, avatar uint8, err error)

GetClientNameAndAvatar returns the displayname and avatar id for the specified user.

func GetMMR

func GetMMR(databaseID uint64) (MMR int, err error)

GetMMR returns the current MMR for the specified user.

func Init

func Init()

Init should be called at the start of the function. It opens a connection to the database based on the parameters defined by environment variables, as specified by the EnvironmentVariables struct.

func SetMatchResult

func SetMatchResult(matchID uint64, winnerDatabaseID uint64) (err error)

SetMatchResult updates the specified match with the winner, end time, and sets phase to 2 (finished).

func SetMatchStart

func SetMatchStart(matchID uint64) (err error)

SetMatchStart updates the phase + start time column for the specified match.

func ValidateAuth

func ValidateAuth(publicID string, authToken string) (databaseID uint64, err error)

ValidateAuth checks the specified database ID and token to see if they match and are valid.

func ValidateMatch

func ValidateMatch(databaseID uint64, matchID uint64) (valid bool, err error)

ValidateMatch returns true if the specified match exists, and the specified client is part of it.

Types

type EnvironmentVariables

type EnvironmentVariables struct {
	DBUsername    string
	DBPass        string
	DBURL         string
	DBPort        string
	DBName        string
	TableUsers    string
	TableProfiles string
	TableMatches  string
	TableTokens   string
}

EnvironmentVariables is a light wrapper for the environment variables required by the database package.

func (*EnvironmentVariables) Load

func (ev *EnvironmentVariables) Load() error

Load attempts to read in all the required environment variables.

type PreparedStatements

type PreparedStatements struct {
	GetUser         string
	GetAuthExpiry   string
	GetMMR          string
	CreateMatch     string
	CheckMatchValid string
	GetDisplayName  string
	GetAvatar       string
	SetMatchStart   string
	SetMatchResult  string
}

PreparedStatements is a light wrapper for all the prepared statements used in this package.

func (*PreparedStatements) Construct

func (p *PreparedStatements) Construct(envvars *EnvironmentVariables)

Construct constructs all the prepared statements for this PreparedStatements object.

Jump to

Keyboard shortcuts

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