// create new weapon stat and return its ID func NewWeaponStat(store store.DBConn, ws WeaponStat) uint { db := store.Conn() db.Create(&ws) return ws.ID }
// create new item stat and return its ID func NewItemStat(store store.DBConn, is ItemStat) uint { db := store.Conn() db.Create(&is) return is.ID }
func NewPlayerMatchStat(store store.DBConn, pms PlayerMatchStat) uint { db := store.Conn() db.Create(&pms) return pms.ID }
// create or lookup a matching alias and return its ID func NewAliasOrCurrent(store store.DBConn, newalias Alias) uint { db := store.Conn() var alias Alias db.FirstOrCreate(&alias, newalias) return alias.ID }
func ListPlayers(store store.DBConn) []Player { db := store.Conn() var players []Player db.Find(&players) return players }
// create new match and return its ID func NewMatch(store store.DBConn, match Match) uint { db := store.Conn() db.Create(&match) return match.ID }
// return alphabetically ordered list of aliases func GetAliases(store store.DBConn, user uint) []Alias { var aliases []Alias store.Conn(). Model(&Alias{}). Where("player_id = ?", user). Order("alias"). Find(&aliases) return aliases }
// find alias using alias ID func GetAlias(store store.DBConn, aliasID uint) *Alias { db := store.Conn() var alias Alias nf := db.First(&alias, aliasID).RecordNotFound() if nf == true { return nil } return &alias }
// list weapon statistics for given player match stat ID func ListWeaponStats(store store.DBConn, pmsID uint) []WeaponStat { db := store.Conn() var ws []WeaponStat db.Where(&WeaponStat{ PlayerMatchStatID: pmsID, }).Find(&ws) return ws }
// list weapon statistics for given player match stat ID func ListItemStats(store store.DBConn, pmsID uint) []ItemStat { db := store.Conn() var is []ItemStat db.Where(&ItemStat{ PlayerMatchStatID: pmsID, }).Find(&is) return is }
func ListPlayerMatchStat(store store.DBConn, matchID uint) []PlayerMatchStat { db := store.Conn() // locate all players in this match var pls []PlayerMatchStat db.Where(&PlayerMatchStat{MatchID: matchID}). Find(&pls) return pls }
// create new player returning its ID func NewPlayer(store store.DBConn, name string, passwordhash string) uint { player := Player{ Name: name, PasswordHash: passwordhash, } db := store.Conn() db.Create(&player) return player.ID }
func GetPlayer(store store.DBConn, pid uint) *Player { db := store.Conn() var player Player notfound := db.First(&player, pid). RecordNotFound() if notfound == true { return nil } return &player }
func FindMatchByHash(store store.DBConn, hash string) *Match { db := store.Conn() var mfound Match notfound := db.Where("data_hash = ?", hash). Find(&mfound). RecordNotFound() if notfound == true { return nil } return &mfound }
func ClaimAliasesByPlayer(store store.DBConn, player uint, aliases []string) { // update aliases set player_id = `player` where aliases in // `aliases`? db := store.Conn() tx := db.Begin() for _, a := range aliases { tx.Model(&Alias{}). Where(&Alias{Alias: a}). Update("player_id", player) } tx.Commit() }
func HasPlayer(store store.DBConn, name string) bool { db := store.Conn() var player Player notfound := db.Where(&Player{Name: name}). First(&player). RecordNotFound() if notfound == true { return false } return true }
func ListMatches(store store.DBConn, params MatchListParams) []Match { db := store.Conn() var matches []Match if params.Limit != 0 { db = db.Limit(params.Limit) } if params.TimeSort == true { ord := "date_time" if params.SortDesc == true { ord += " desc" } db = db.Order(ord) } db.Find(&matches) return matches }
func CreateSchema(store store.DBConn) error { store.Conn().AutoMigrate(schemaModels...) return nil }