persistence

package
v0.0.0-...-e6e1fff Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddBet

func AddBet(q Querier, bet *Bet) (int, error)

INSERT

func AddCompetition

func AddCompetition(q Querier, competition *Competition) (string, error)

func AddOfferedBet

func AddOfferedBet(q Querier, ob *OfferedBet) (int, error)

func AddUser

func AddUser(q Querier, user *User) (int, error)

INSERT

func AgreeToBet

func AgreeToBet(q Querier, betId int, userN int, agreed bool) (int, error)

UPDATE

func CheckUsername

func CheckUsername(q Querier, username string) (bool, error)

case insensitive true means username can be used, false means it cannot be used

func ConnectDb

func ConnectDb() *sqlx.DB

func CountUserWinLoss

func CountUserWinLoss(q Querier, userId int) (int, int, error)

counts

func Experiments

func Experiments(q Querier)

func OfferedBetNameById

func OfferedBetNameById(q Querier, offeredBetId int) (string, error)

func OneHashByName

func OneHashByName(q Querier, username string) (string, error)

case insensitive

func OneUserIdByName

func OneUserIdByName(q Querier, username string) (int, error)

case insensitive

func OneUsername

func OneUsername(q Querier, userId int) (string, error)

func SeedDb

func SeedDb(db *sqlx.DB)

TODO improve performance using transactions or concurrency

func UpdateBet

func UpdateBet(q Querier, bet *Bet) (int, error)

func UpdateCompetition

func UpdateCompetition(q Querier, competition *Competition) (string, error)

one

func UpdateOfferedBet

func UpdateOfferedBet(q Querier, ob *OfferedBet) (int, error)

Types

type Bet

type Bet struct {
	BetId        int `db:"bet_id"`
	BetStatus    int `db:"bet_status"`
	Amount1      int
	Outcome1Odds int
	User1Agreed  bool
	User1Id      int
	Amount2      int
	Outcome2Odds int
	User2Agreed  bool
	User2Id      int
	PointSpread  float32 `db:"point_spread"`
	Customized   bool
	OfferedBetId int `db:"offered_bet_id"`
	Settled      bool
}

func BetsByOfferedBet

func BetsByOfferedBet(q Querier, offeredBetId int) ([]Bet, error)

func BetsByUser

func BetsByUser(q Querier, user_id int) ([]Bet, error)

func OneBet

func OneBet(q Querier, betId int) (Bet, error)

type BetAndUser

type BetAndUser struct {
	BetId        int `db:"bet_id"`
	BetStatus    int `db:"bet_status"`
	Amount1      int
	Outcome1Odds int
	User1Agreed  bool
	User1Id      int
	Amount2      int
	Outcome2Odds int
	User2Agreed  bool
	User2Id      int
	PointSpread  float32 `db:"point_spread"`
	OfferedBetId int     `db:"offered_bet_id"`
	Settled      bool

	Username1 string
	Balance1  float64

	Username2 string
	Balance2  float64

	ObName    string `db:"offered_bet_name"`
	Outcome1  string
	Outcome2  string
	EventDate time.Time `db:"event_date"`
}

JOINED TYPES

func BetAndUsersByBetId

func BetAndUsersByBetId(q Querier, betId int) (*BetAndUser, error)

joins

func BetsAndObsAndUsersByUserId

func BetsAndObsAndUsersByUserId(q Querier, userId int) ([]BetAndUser, error)

type Competition

type Competition struct {
	CompetitionId   string    `db:"competition_id"`
	CompetitionName string    `db:"competition_name"`
	EventStatus     int       `db:"event_status"`
	EventDate       time.Time `db:"event_date"`
}

func AllCompetitions

func AllCompetitions(q Querier) ([]Competition, error)

many

func OneCompetition

func OneCompetition(q Querier, competitionId string) (*Competition, error)

type OfferedBet

type OfferedBet struct {
	OfferedBetId   int    `db:"offered_bet_id"`
	OfferedBetName string `db:"offered_bet_name"`
	Outcome1       string
	Outcome1Odds   int
	Outcome2       string
	Outcome2Odds   int
	PointSpread    float32   `db:"point_spread"`
	EventDate      time.Time `db:"event_date"`
	EventStatus    int       `db:"event_status"`
	CompetitionId  string    `db:"competition_id"`
}

func OfferedBetsByCompetiton

func OfferedBetsByCompetiton(q Querier, competitionId string) ([]OfferedBet, error)

func OneOfferedBet

func OneOfferedBet(q Querier, offeredBetId int) (*OfferedBet, error)

one

type Querier

type Querier interface {
	sqlx.Execer
	sqlx.Queryer
	Select(dest interface{}, query string, args ...interface{}) error
	Get(dest interface{}, query string, args ...interface{}) error
}

type User

type User struct {
	UserId   int `db:"user_id"`
	Username string
	Balance  float64
	Hash     string
}

func AllUsers

func AllUsers(q Querier) ([]User, error)

many

func OneUser

func OneUser(q Querier, userId int) (User, error)

func OneUserByName

func OneUserByName(q Querier, username string) (User, error)

case insensitive

Jump to

Keyboard shortcuts

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