db

package
v0.0.0-...-0653a19 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package db contains bet/account/player/signature related CRUD functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Address string `db:"address"`
	Nonce   int    `db:"nonce"`
}

Account represents an individual account.

type Bet

type Bet struct {
	ID               string    `db:"bet_id"`
	Status           string    `db:"status_id"`
	Description      string    `db:"description"`
	Terms            string    `db:"terms"`
	Amount           int       `db:"amount"`
	ModeratorAddress string    `db:"moderator_address"`
	DateExpired      time.Time `db:"date_expired"`
	DateCreated      time.Time `db:"date_created"`
	DateUpdated      time.Time `db:"date_updated"`
}

Bet represents an individual bet.

type Player

type Player struct {
	BetID   string `db:"bet_id"`
	Address string `db:"address"`
	InFavor bool   `db:"in_favor"`
}

Player represents the connection between a Bet and an Account that is in a player role.

type Signature

type Signature struct {
	BetID      string    `db:"bet_id"`
	Address    string    `db:"address"`
	Nonce      int       `db:"nonce"`
	Signature  string    `db:"signature"`
	DateSigned time.Time `db:"date_signed"`
}

Signature represents an individual signature by an Account on a Bet.

type Store

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

Store manages the set of APIs for bet access.

func NewStore

func NewStore(log *zap.SugaredLogger, db *sqlx.DB) Store

NewStore constructs a data for api access.

func (Store) AddPlayer

func (s Store) AddPlayer(ctx context.Context, player Player) error

AddPlayer adds a new player to an existing bet.

func (Store) AddSignature

func (s Store) AddSignature(ctx context.Context, signature Signature) error

AddSignature adds a new player signature to an existing bet.

func (Store) CreateAccount

func (s Store) CreateAccount(ctx context.Context, account Account) error

CreateAccount inserts a new Account into the database.

func (Store) CreateBet

func (s Store) CreateBet(ctx context.Context, bet Bet) error

CreateBet inserts a new Bet into the database.

func (Store) DeleteBet

func (s Store) DeleteBet(ctx context.Context, betID string) error

DeleteBet removes a bet from the database.

func (Store) QueryAccountByAddress

func (s Store) QueryAccountByAddress(ctx context.Context, address string) (Account, error)

QueryAccountByAddress QueryAccountsByAddress retrieves an account by address.

func (Store) QueryAccounts

func (s Store) QueryAccounts(ctx context.Context, pageNumber, rowsPerPage int) ([]Account, error)

QueryAccounts retrieves a list of existing accounts from the database.

func (Store) QueryBet

func (s Store) QueryBet(ctx context.Context, pageNumber int, rowsPerPage int) ([]Bet, error)

QueryBet retrieves a list of existing bets from the database.

func (Store) QueryBetByExpiration

func (s Store) QueryBetByExpiration(ctx context.Context, start, end time.Time, pageNumber int, rowsPerPage int) ([]Bet, error)

QueryBetByExpiration queries bets by expiration date by providing a start and end time.

func (Store) QueryBetByID

func (s Store) QueryBetByID(ctx context.Context, betID string) (Bet, error)

QueryBetByID gets the specified bet from the database.

func (Store) QueryBetByModeratorAddress

func (s Store) QueryBetByModeratorAddress(ctx context.Context, moderatorAddress string, pageNumber int, rowsPerPage int) ([]Bet, error)

QueryBetByModeratorAddress retrieves all bets with the specified address as a moderator for the bet.

func (Store) QueryBetByPlayerAddress

func (s Store) QueryBetByPlayerAddress(ctx context.Context, playerAddress string, pageNumber int, rowsPerPage int) ([]Bet, error)

QueryBetByPlayerAddress retrieves all bets filtering by a player address.

func (Store) QueryBetByStatus

func (s Store) QueryBetByStatus(ctx context.Context, status string, pageNumber int, rowsPerPage int) ([]Bet, error)

QueryBetByStatus queries bets by their status.

func (Store) QueryBetPlayers

func (s Store) QueryBetPlayers(ctx context.Context, betID string, pageNumber int, rowsPerPage int) ([]Player, error)

QueryBetPlayers queries bets_players by bet ID.

func (Store) QueryBetSignatures

func (s Store) QueryBetSignatures(ctx context.Context, betID string, pageNumber int, rowsPerPage int) ([]Signature, error)

QueryBetSignatures queries bets_signatures by bet ID.

func (Store) Tran

func (s Store) Tran(tx sqlx.ExtContext) Store

Tran return new Store with transaction in it.

func (Store) UpdateAccount

func (s Store) UpdateAccount(ctx context.Context, account Account) error

UpdateAccount updates an existing account in the database.

func (Store) UpdateBet

func (s Store) UpdateBet(ctx context.Context, bet Bet) error

UpdateBet replaces a bet in the database.

func (Store) WithinTran

func (s Store) WithinTran(ctx context.Context, fn func(sqlx.ExtContext) error) error

WithinTran runs passed function and do commit/rollback at the end.

Jump to

Keyboard shortcuts

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