// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.30.0 // source: bet_stat.sql package dbgen import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const GetBetStats = `-- name: GetBetStats :many SELECT DATE(created_at) as date, COUNT(*) as total_bets, SUM(amount) as total_stakes, SUM( CASE WHEN status = 1 THEN 1 ELSE 0 END ) as total_wins, SUM( CASE WHEN status = 1 THEN amount * total_odds ELSE 0 END ) as total_payouts, AVG(total_odds) as average_odds FROM bets wHERE ( user_id = $1 OR $1 IS NULL ) AND ( is_shop_bet = $2 OR $2 IS NULL ) AND ( cashed_out = $3 OR $3 IS NULL ) AND ( full_name ILIKE '%' || $4 || '%' OR phone_number ILIKE '%' || $4 || '%' OR $4 IS NULL ) AND ( created_at > $5 OR $5 IS NULL ) AND ( created_at < $6 OR $6 IS NULL ) GROUP BY DATE(created_at) ORDER BY DATE(created_at) ` type GetBetStatsParams struct { UserID pgtype.Int8 `json:"user_id"` IsShopBet pgtype.Bool `json:"is_shop_bet"` CashedOut pgtype.Bool `json:"cashed_out"` Query pgtype.Text `json:"query"` CreatedBefore pgtype.Timestamp `json:"created_before"` CreatedAfter pgtype.Timestamp `json:"created_after"` } type GetBetStatsRow struct { Date pgtype.Date `json:"date"` TotalBets int64 `json:"total_bets"` TotalStakes int64 `json:"total_stakes"` TotalWins int64 `json:"total_wins"` TotalPayouts int64 `json:"total_payouts"` AverageOdds float64 `json:"average_odds"` } func (q *Queries) GetBetStats(ctx context.Context, arg GetBetStatsParams) ([]GetBetStatsRow, error) { rows, err := q.db.Query(ctx, GetBetStats, arg.UserID, arg.IsShopBet, arg.CashedOut, arg.Query, arg.CreatedBefore, arg.CreatedAfter, ) if err != nil { return nil, err } defer rows.Close() var items []GetBetStatsRow for rows.Next() { var i GetBetStatsRow if err := rows.Scan( &i.Date, &i.TotalBets, &i.TotalStakes, &i.TotalWins, &i.TotalPayouts, &i.AverageOdds, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const GetBetSummary = `-- name: GetBetSummary :one SELECT SUM(amount) as total_stakes, COUNT(*) as total_bets, SUM( CASE WHEN status = 0 THEN 1 ELSE 0 END ) as active_bets, SUM( CASE WHEN status = 1 THEN 1 ELSE 0 END ) as total_wins, SUM( CASE WHEN status = 2 THEN 1 ELSE 0 END ) as total_losses, SUM( CASE WHEN status = 1 THEN amount * total_odds ELSE 0 END ) as win_balance FROM bets wHERE ( user_id = $1 OR $1 IS NULL ) AND ( created_at > $2 OR $2 IS NULL ) AND ( created_at < $3 OR $3 IS NULL ) ` type GetBetSummaryParams struct { UserID pgtype.Int8 `json:"user_id"` CreatedBefore pgtype.Timestamp `json:"created_before"` CreatedAfter pgtype.Timestamp `json:"created_after"` } type GetBetSummaryRow struct { TotalStakes int64 `json:"total_stakes"` TotalBets int64 `json:"total_bets"` ActiveBets int64 `json:"active_bets"` TotalWins int64 `json:"total_wins"` TotalLosses int64 `json:"total_losses"` WinBalance int64 `json:"win_balance"` } func (q *Queries) GetBetSummary(ctx context.Context, arg GetBetSummaryParams) (GetBetSummaryRow, error) { row := q.db.QueryRow(ctx, GetBetSummary, arg.UserID, arg.CreatedBefore, arg.CreatedAfter) var i GetBetSummaryRow err := row.Scan( &i.TotalStakes, &i.TotalBets, &i.ActiveBets, &i.TotalWins, &i.TotalLosses, &i.WinBalance, ) return i, err } const GetMarketPopularity = `-- name: GetMarketPopularity :one WITH market_counts AS ( SELECT DATE(b.created_at) as date, bo.market_name, COUNT(*) as bet_count, ROW_NUMBER() OVER ( PARTITION BY DATE(b.created_at) ORDER BY COUNT(*) DESC ) as rank FROM bets b JOIN bet_outcomes bo ON b.id = bo.bet_id WHERE bo.market_name IS NOT NULL AND ( user_id = $1 OR $1 IS NULL ) AND ( created_at > $2 OR $2 IS NULL ) AND ( created_at < $3 OR $3 IS NULL ) GROUP BY DATE(b.created_at), bo.market_name ) SELECT date, market_name FROM market_counts WHERE rank = 1 ` type GetMarketPopularityParams struct { UserID pgtype.Int8 `json:"user_id"` CreatedBefore pgtype.Timestamp `json:"created_before"` CreatedAfter pgtype.Timestamp `json:"created_after"` } type GetMarketPopularityRow struct { Date pgtype.Date `json:"date"` MarketName string `json:"market_name"` } func (q *Queries) GetMarketPopularity(ctx context.Context, arg GetMarketPopularityParams) (GetMarketPopularityRow, error) { row := q.db.QueryRow(ctx, GetMarketPopularity, arg.UserID, arg.CreatedBefore, arg.CreatedAfter) var i GetMarketPopularityRow err := row.Scan(&i.Date, &i.MarketName) return i, err } const GetTotalBetsMadeInRange = `-- name: GetTotalBetsMadeInRange :one SELECT COUNT(*) AS total_bets FROM bets WHERE created_at BETWEEN $1 AND $2 ` type GetTotalBetsMadeInRangeParams struct { From pgtype.Timestamp `json:"from"` To pgtype.Timestamp `json:"to"` } func (q *Queries) GetTotalBetsMadeInRange(ctx context.Context, arg GetTotalBetsMadeInRangeParams) (int64, error) { row := q.db.QueryRow(ctx, GetTotalBetsMadeInRange, arg.From, arg.To) var total_bets int64 err := row.Scan(&total_bets) return total_bets, err } const GetTotalCashBacksInRange = `-- name: GetTotalCashBacksInRange :one SELECT COALESCE(SUM(amount), 0) AS total_cash_backs FROM bets WHERE created_at BETWEEN $1 AND $2 AND status = 5 ` type GetTotalCashBacksInRangeParams struct { From pgtype.Timestamp `json:"from"` To pgtype.Timestamp `json:"to"` } func (q *Queries) GetTotalCashBacksInRange(ctx context.Context, arg GetTotalCashBacksInRangeParams) (interface{}, error) { row := q.db.QueryRow(ctx, GetTotalCashBacksInRange, arg.From, arg.To) var total_cash_backs interface{} err := row.Scan(&total_cash_backs) return total_cash_backs, err } const GetTotalCashMadeInRange = `-- name: GetTotalCashMadeInRange :one SELECT COALESCE(SUM(amount), 0) AS total_cash_made FROM bets WHERE created_at BETWEEN $1 AND $2 ` type GetTotalCashMadeInRangeParams struct { From pgtype.Timestamp `json:"from"` To pgtype.Timestamp `json:"to"` } func (q *Queries) GetTotalCashMadeInRange(ctx context.Context, arg GetTotalCashMadeInRangeParams) (interface{}, error) { row := q.db.QueryRow(ctx, GetTotalCashMadeInRange, arg.From, arg.To) var total_cash_made interface{} err := row.Scan(&total_cash_made) return total_cash_made, err } const GetTotalCashOutInRange = `-- name: GetTotalCashOutInRange :one SELECT COALESCE(SUM(amount), 0) AS total_cash_out FROM bets WHERE created_at BETWEEN $1 AND $2 AND cashed_out = true ` type GetTotalCashOutInRangeParams struct { From pgtype.Timestamp `json:"from"` To pgtype.Timestamp `json:"to"` } func (q *Queries) GetTotalCashOutInRange(ctx context.Context, arg GetTotalCashOutInRangeParams) (interface{}, error) { row := q.db.QueryRow(ctx, GetTotalCashOutInRange, arg.From, arg.To) var total_cash_out interface{} err := row.Scan(&total_cash_out) return total_cash_out, err }