database

package
v0.0.0-...-165beb6 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2022 License: MIT Imports: 11 Imported by: 3

Documentation

Index

Constants

View Source
const (
	QueryGetSummonerByName      = "getSummonerByName"
	QueryGetSummonerByAccountId = "getSummonerByAccountId"
	QueryGetSummonerByCacheID   = "getSummonerByCacheID"
	QueryUpsertSummoner         = "upsertSummoner"
)

Queries that are prepared for easy calling

View Source
const (
	QueryGetTeams       = "getTeams"
	QueryGetRandomTeams = "getRandomTeams"
	QueryInsertTeam     = "insertTeam"
	QueryUpdateTeam     = "updateTeam"
	QueryDeleteTeam     = "deleteTeam"
)

Queries that are prepared for easy calling

View Source
const (
	QueryGetUserAccountByUsername = "getUserAccount"
	QueryPutUserAccount           = "putUserAccount"
	QueryGetUsername              = "getUsername"
)

Queries that are prepared for easy calling

View Source
const (
	QueryGetSessionUserID = "getSession"
	QueryPutSession       = "putSession"
	QueryDeleteSession    = "deleteSession"
)

Queries that are prepared for easy calling

View Source
const BcryptCost = 13

BcryptCost increases the number of rounds and time taken by the hash algorithm; safe to change this since the number of rounds is stored in the bcrypt hash, so will only apply to new passwords

View Source
const DBTimeout = 30 * time.Second

DBTimeout in seconds

View Source
const InsertionAttempts = 5

InsertionAttempts to generate a session ID. Honestly we should never even have a conflict

View Source
const MaxDBConnections = 5

MaxDBConnections the db can support

View Source
const SessionIDLength = 64

Variables

View Source
var DBConnectionPool *pgx.ConnPool

DBConnectionPool is required for making queries to the DB

Functions

func AddSession

func AddSession(userID int64) (string, error)

AddSession to the database

func AddTeam

func AddTeam(owner int64, teamName string, region string, position int,
	top int64, jungle int64, mid int64, bottom int64, support int64) error

AddTeam to database, errors if team already exists in that slot

func CacheSummoner

func CacheSummoner(region string, normalizedName string, summoner rgapi.Summoner) (int64, error)

CacheSummoner attempts to cache a summoner if it hasn't been cached before

func Connect

func Connect() error

Connect to the database

func DeleteSession

func DeleteSession(sessionID string) error

DeleteSession from the database

func DeleteTeam

func DeleteTeam(teamID int64) error

DeleteTeam that already exists in the database

func GetRandomTeams

func GetRandomTeams(numTeams int) (*[]FantasyTeam, error)

GetRandomTeams tries to retrieve numTeams non-bench fantasy teams from the DB

func GetTeams

func GetTeams(userID int64) (*[]FantasyTeam, error)

GetTeams for the given user id from the database if they exist

func GetUserIDFromSession

func GetUserIDFromSession(sessionID string) (int64, error)

GetUserIDFromSession database table

func GetUsername

func GetUsername(userID int64) (string, error)

GetUsername for given user ID

func Login

func Login(username string, password string) (string, error)

Login a user account from the db

func PreparePepper

func PreparePepper() error

PreparePepper gets the pepper value from environment variables

func Register

func Register(username string, password string) (string, error)

Register a new account to the db

func UncacheSummonerByAccountId

func UncacheSummonerByAccountId(region string, accountId int64) (rgapi.Summoner, int64, error)

UncacheSummonerByAccountId from database if it exists, return an error otherwise TODO: Do this in bulk, and perform the Riot API queries/caching here

func UncacheSummonerByCacheID

func UncacheSummonerByCacheID(summonerCacheID int64) (rgapi.Summoner, error)

UncacheSummonerByCacheID from database if it exists, return an error otherwise

func UncacheSummonerByName

func UncacheSummonerByName(region string, normalizedName string) (rgapi.Summoner, int64, error)

UncacheSummonerByName from database if it exists, return an error otherwise TODO: Do this in bulk, and perform the Riot API queries/caching here

func UpdateTeam

func UpdateTeam(teamID int64, owner int64, teamName string, region string, position int,
	top int64, jungle int64, mid int64, bottom int64, support int64) error

UpdateTeam that already exists in the database

Types

type FantasyTeam

type FantasyTeam struct {
	ID       int64
	Owner    int64
	Name     string
	Region   string
	Position int
	Top      int64
	Jungle   int64
	Mid      int64
	Bottom   int64
	Support  int64
}

FantasyTeam contains the account IDs and meta information for a fantasy team

Jump to

Keyboard shortcuts

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