278 lines
6.4 KiB
Go
278 lines
6.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.28.0
|
|
// source: bet.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const CreateBet = `-- name: CreateBet :one
|
|
INSERT INTO bets (
|
|
amount,
|
|
total_odds,
|
|
status,
|
|
full_name,
|
|
phone_number,
|
|
branch_id,
|
|
user_id,
|
|
is_shop_bet,
|
|
cashout_id
|
|
)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
RETURNING id, amount, total_odds, status, full_name, phone_number, branch_id, user_id, cashed_out, cashout_id, created_at, updated_at, is_shop_bet
|
|
`
|
|
|
|
type CreateBetParams struct {
|
|
Amount int64 `json:"amount"`
|
|
TotalOdds float32 `json:"total_odds"`
|
|
Status int32 `json:"status"`
|
|
FullName string `json:"full_name"`
|
|
PhoneNumber string `json:"phone_number"`
|
|
BranchID pgtype.Int8 `json:"branch_id"`
|
|
UserID pgtype.Int8 `json:"user_id"`
|
|
IsShopBet bool `json:"is_shop_bet"`
|
|
CashoutID string `json:"cashout_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateBet(ctx context.Context, arg CreateBetParams) (Bet, error) {
|
|
row := q.db.QueryRow(ctx, CreateBet,
|
|
arg.Amount,
|
|
arg.TotalOdds,
|
|
arg.Status,
|
|
arg.FullName,
|
|
arg.PhoneNumber,
|
|
arg.BranchID,
|
|
arg.UserID,
|
|
arg.IsShopBet,
|
|
arg.CashoutID,
|
|
)
|
|
var i Bet
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Amount,
|
|
&i.TotalOdds,
|
|
&i.Status,
|
|
&i.FullName,
|
|
&i.PhoneNumber,
|
|
&i.BranchID,
|
|
&i.UserID,
|
|
&i.CashedOut,
|
|
&i.CashoutID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.IsShopBet,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
type CreateBetOutcomeParams struct {
|
|
BetID int64 `json:"bet_id"`
|
|
EventID int64 `json:"event_id"`
|
|
OddID int64 `json:"odd_id"`
|
|
HomeTeamName string `json:"home_team_name"`
|
|
AwayTeamName string `json:"away_team_name"`
|
|
MarketID int64 `json:"market_id"`
|
|
MarketName string `json:"market_name"`
|
|
Odd float32 `json:"odd"`
|
|
OddName string `json:"odd_name"`
|
|
OddHeader string `json:"odd_header"`
|
|
OddHandicap string `json:"odd_handicap"`
|
|
Expires pgtype.Timestamp `json:"expires"`
|
|
}
|
|
|
|
const DeleteBet = `-- name: DeleteBet :exec
|
|
DELETE FROM bets
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteBet(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, DeleteBet, id)
|
|
return err
|
|
}
|
|
|
|
const DeleteBetOutcome = `-- name: DeleteBetOutcome :exec
|
|
DELETE FROM bet_outcomes
|
|
WHERE bet_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteBetOutcome(ctx context.Context, betID int64) error {
|
|
_, err := q.db.Exec(ctx, DeleteBetOutcome, betID)
|
|
return err
|
|
}
|
|
|
|
const GetAllBets = `-- name: GetAllBets :many
|
|
SELECT id, amount, total_odds, status, full_name, phone_number, branch_id, user_id, cashed_out, cashout_id, created_at, updated_at, is_shop_bet, outcomes
|
|
FROM bet_with_outcomes
|
|
`
|
|
|
|
func (q *Queries) GetAllBets(ctx context.Context) ([]BetWithOutcome, error) {
|
|
rows, err := q.db.Query(ctx, GetAllBets)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []BetWithOutcome
|
|
for rows.Next() {
|
|
var i BetWithOutcome
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Amount,
|
|
&i.TotalOdds,
|
|
&i.Status,
|
|
&i.FullName,
|
|
&i.PhoneNumber,
|
|
&i.BranchID,
|
|
&i.UserID,
|
|
&i.CashedOut,
|
|
&i.CashoutID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.IsShopBet,
|
|
&i.Outcomes,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetBetByBranchID = `-- name: GetBetByBranchID :many
|
|
SELECT id, amount, total_odds, status, full_name, phone_number, branch_id, user_id, cashed_out, cashout_id, created_at, updated_at, is_shop_bet, outcomes
|
|
FROM bet_with_outcomes
|
|
WHERE branch_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetBetByBranchID(ctx context.Context, branchID pgtype.Int8) ([]BetWithOutcome, error) {
|
|
rows, err := q.db.Query(ctx, GetBetByBranchID, branchID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []BetWithOutcome
|
|
for rows.Next() {
|
|
var i BetWithOutcome
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Amount,
|
|
&i.TotalOdds,
|
|
&i.Status,
|
|
&i.FullName,
|
|
&i.PhoneNumber,
|
|
&i.BranchID,
|
|
&i.UserID,
|
|
&i.CashedOut,
|
|
&i.CashoutID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.IsShopBet,
|
|
&i.Outcomes,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetBetByCashoutID = `-- name: GetBetByCashoutID :one
|
|
SELECT id, amount, total_odds, status, full_name, phone_number, branch_id, user_id, cashed_out, cashout_id, created_at, updated_at, is_shop_bet, outcomes
|
|
FROM bet_with_outcomes
|
|
WHERE cashout_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetBetByCashoutID(ctx context.Context, cashoutID string) (BetWithOutcome, error) {
|
|
row := q.db.QueryRow(ctx, GetBetByCashoutID, cashoutID)
|
|
var i BetWithOutcome
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Amount,
|
|
&i.TotalOdds,
|
|
&i.Status,
|
|
&i.FullName,
|
|
&i.PhoneNumber,
|
|
&i.BranchID,
|
|
&i.UserID,
|
|
&i.CashedOut,
|
|
&i.CashoutID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.IsShopBet,
|
|
&i.Outcomes,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetBetByID = `-- name: GetBetByID :one
|
|
SELECT id, amount, total_odds, status, full_name, phone_number, branch_id, user_id, cashed_out, cashout_id, created_at, updated_at, is_shop_bet, outcomes
|
|
FROM bet_with_outcomes
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetBetByID(ctx context.Context, id int64) (BetWithOutcome, error) {
|
|
row := q.db.QueryRow(ctx, GetBetByID, id)
|
|
var i BetWithOutcome
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Amount,
|
|
&i.TotalOdds,
|
|
&i.Status,
|
|
&i.FullName,
|
|
&i.PhoneNumber,
|
|
&i.BranchID,
|
|
&i.UserID,
|
|
&i.CashedOut,
|
|
&i.CashoutID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.IsShopBet,
|
|
&i.Outcomes,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const UpdateCashOut = `-- name: UpdateCashOut :exec
|
|
UPDATE bets
|
|
SET cashed_out = $2,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateCashOutParams struct {
|
|
ID int64 `json:"id"`
|
|
CashedOut bool `json:"cashed_out"`
|
|
}
|
|
|
|
func (q *Queries) UpdateCashOut(ctx context.Context, arg UpdateCashOutParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateCashOut, arg.ID, arg.CashedOut)
|
|
return err
|
|
}
|
|
|
|
const UpdateStatus = `-- name: UpdateStatus :exec
|
|
UPDATE bets
|
|
SET status = $2,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateStatusParams struct {
|
|
ID int64 `json:"id"`
|
|
Status int32 `json:"status"`
|
|
}
|
|
|
|
func (q *Queries) UpdateStatus(ctx context.Context, arg UpdateStatusParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateStatus, arg.ID, arg.Status)
|
|
return err
|
|
}
|