575 lines
16 KiB
Go
575 lines
16 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: virtual_games.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const AddFavoriteGame = `-- name: AddFavoriteGame :exec
|
|
INSERT INTO favorite_games (
|
|
user_id,
|
|
game_id,
|
|
created_at
|
|
) VALUES ($1, $2, NOW())
|
|
ON CONFLICT (user_id, game_id) DO NOTHING
|
|
`
|
|
|
|
type AddFavoriteGameParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
GameID int64 `json:"game_id"`
|
|
}
|
|
|
|
func (q *Queries) AddFavoriteGame(ctx context.Context, arg AddFavoriteGameParams) error {
|
|
_, err := q.db.Exec(ctx, AddFavoriteGame, arg.UserID, arg.GameID)
|
|
return err
|
|
}
|
|
|
|
const CountVirtualGameProviders = `-- name: CountVirtualGameProviders :one
|
|
SELECT COUNT(*) AS total
|
|
FROM virtual_game_providers
|
|
`
|
|
|
|
func (q *Queries) CountVirtualGameProviders(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRow(ctx, CountVirtualGameProviders)
|
|
var total int64
|
|
err := row.Scan(&total)
|
|
return total, err
|
|
}
|
|
|
|
const CreateVirtualGameHistory = `-- name: CreateVirtualGameHistory :one
|
|
INSERT INTO virtual_game_histories (
|
|
session_id,
|
|
user_id,
|
|
company_id,
|
|
provider,
|
|
wallet_id,
|
|
game_id,
|
|
transaction_type,
|
|
amount,
|
|
currency,
|
|
external_transaction_id,
|
|
reference_transaction_id,
|
|
status
|
|
) VALUES (
|
|
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
|
|
) RETURNING
|
|
id,
|
|
session_id,
|
|
user_id,
|
|
company_id,
|
|
provider,
|
|
wallet_id,
|
|
game_id,
|
|
transaction_type,
|
|
amount,
|
|
currency,
|
|
external_transaction_id,
|
|
reference_transaction_id,
|
|
status,
|
|
created_at,
|
|
updated_at
|
|
`
|
|
|
|
type CreateVirtualGameHistoryParams struct {
|
|
SessionID pgtype.Text `json:"session_id"`
|
|
UserID int64 `json:"user_id"`
|
|
CompanyID pgtype.Int8 `json:"company_id"`
|
|
Provider pgtype.Text `json:"provider"`
|
|
WalletID pgtype.Int8 `json:"wallet_id"`
|
|
GameID pgtype.Int8 `json:"game_id"`
|
|
TransactionType string `json:"transaction_type"`
|
|
Amount int64 `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
ExternalTransactionID string `json:"external_transaction_id"`
|
|
ReferenceTransactionID pgtype.Text `json:"reference_transaction_id"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
func (q *Queries) CreateVirtualGameHistory(ctx context.Context, arg CreateVirtualGameHistoryParams) (VirtualGameHistory, error) {
|
|
row := q.db.QueryRow(ctx, CreateVirtualGameHistory,
|
|
arg.SessionID,
|
|
arg.UserID,
|
|
arg.CompanyID,
|
|
arg.Provider,
|
|
arg.WalletID,
|
|
arg.GameID,
|
|
arg.TransactionType,
|
|
arg.Amount,
|
|
arg.Currency,
|
|
arg.ExternalTransactionID,
|
|
arg.ReferenceTransactionID,
|
|
arg.Status,
|
|
)
|
|
var i VirtualGameHistory
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.SessionID,
|
|
&i.UserID,
|
|
&i.CompanyID,
|
|
&i.Provider,
|
|
&i.WalletID,
|
|
&i.GameID,
|
|
&i.TransactionType,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.ExternalTransactionID,
|
|
&i.ReferenceTransactionID,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateVirtualGameProvider = `-- name: CreateVirtualGameProvider :one
|
|
INSERT INTO virtual_game_providers (
|
|
provider_id, provider_name, logo_dark, logo_light, enabled
|
|
) VALUES (
|
|
$1, $2, $3, $4, $5
|
|
) RETURNING id, provider_id, provider_name, logo_dark, logo_light, enabled, created_at, updated_at
|
|
`
|
|
|
|
type CreateVirtualGameProviderParams struct {
|
|
ProviderID string `json:"provider_id"`
|
|
ProviderName string `json:"provider_name"`
|
|
LogoDark pgtype.Text `json:"logo_dark"`
|
|
LogoLight pgtype.Text `json:"logo_light"`
|
|
Enabled bool `json:"enabled"`
|
|
}
|
|
|
|
func (q *Queries) CreateVirtualGameProvider(ctx context.Context, arg CreateVirtualGameProviderParams) (VirtualGameProvider, error) {
|
|
row := q.db.QueryRow(ctx, CreateVirtualGameProvider,
|
|
arg.ProviderID,
|
|
arg.ProviderName,
|
|
arg.LogoDark,
|
|
arg.LogoLight,
|
|
arg.Enabled,
|
|
)
|
|
var i VirtualGameProvider
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProviderID,
|
|
&i.ProviderName,
|
|
&i.LogoDark,
|
|
&i.LogoLight,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateVirtualGameSession = `-- name: CreateVirtualGameSession :one
|
|
INSERT INTO virtual_game_sessions (
|
|
user_id, game_id, session_token, currency, status, expires_at
|
|
) VALUES (
|
|
$1, $2, $3, $4, $5, $6
|
|
) RETURNING id, user_id, game_id, session_token, currency, status, created_at, updated_at, expires_at
|
|
`
|
|
|
|
type CreateVirtualGameSessionParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
GameID string `json:"game_id"`
|
|
SessionToken string `json:"session_token"`
|
|
Currency string `json:"currency"`
|
|
Status string `json:"status"`
|
|
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
|
|
}
|
|
|
|
func (q *Queries) CreateVirtualGameSession(ctx context.Context, arg CreateVirtualGameSessionParams) (VirtualGameSession, error) {
|
|
row := q.db.QueryRow(ctx, CreateVirtualGameSession,
|
|
arg.UserID,
|
|
arg.GameID,
|
|
arg.SessionToken,
|
|
arg.Currency,
|
|
arg.Status,
|
|
arg.ExpiresAt,
|
|
)
|
|
var i VirtualGameSession
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.GameID,
|
|
&i.SessionToken,
|
|
&i.Currency,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ExpiresAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateVirtualGameTransaction = `-- name: CreateVirtualGameTransaction :one
|
|
INSERT INTO virtual_game_transactions (
|
|
session_id, user_id, company_id, provider, wallet_id, transaction_type, amount, currency, external_transaction_id, status
|
|
) VALUES (
|
|
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10
|
|
) RETURNING id, session_id, user_id, company_id, provider, wallet_id, transaction_type, amount, currency, external_transaction_id, status, created_at, updated_at
|
|
`
|
|
|
|
type CreateVirtualGameTransactionParams struct {
|
|
SessionID int64 `json:"session_id"`
|
|
UserID int64 `json:"user_id"`
|
|
CompanyID pgtype.Int8 `json:"company_id"`
|
|
Provider pgtype.Text `json:"provider"`
|
|
WalletID int64 `json:"wallet_id"`
|
|
TransactionType string `json:"transaction_type"`
|
|
Amount int64 `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
ExternalTransactionID string `json:"external_transaction_id"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
type CreateVirtualGameTransactionRow struct {
|
|
ID int64 `json:"id"`
|
|
SessionID int64 `json:"session_id"`
|
|
UserID int64 `json:"user_id"`
|
|
CompanyID pgtype.Int8 `json:"company_id"`
|
|
Provider pgtype.Text `json:"provider"`
|
|
WalletID int64 `json:"wallet_id"`
|
|
TransactionType string `json:"transaction_type"`
|
|
Amount int64 `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
ExternalTransactionID string `json:"external_transaction_id"`
|
|
Status string `json:"status"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) CreateVirtualGameTransaction(ctx context.Context, arg CreateVirtualGameTransactionParams) (CreateVirtualGameTransactionRow, error) {
|
|
row := q.db.QueryRow(ctx, CreateVirtualGameTransaction,
|
|
arg.SessionID,
|
|
arg.UserID,
|
|
arg.CompanyID,
|
|
arg.Provider,
|
|
arg.WalletID,
|
|
arg.TransactionType,
|
|
arg.Amount,
|
|
arg.Currency,
|
|
arg.ExternalTransactionID,
|
|
arg.Status,
|
|
)
|
|
var i CreateVirtualGameTransactionRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.SessionID,
|
|
&i.UserID,
|
|
&i.CompanyID,
|
|
&i.Provider,
|
|
&i.WalletID,
|
|
&i.TransactionType,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.ExternalTransactionID,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const DeleteAllVirtualGameProviders = `-- name: DeleteAllVirtualGameProviders :exec
|
|
DELETE FROM virtual_game_providers
|
|
`
|
|
|
|
func (q *Queries) DeleteAllVirtualGameProviders(ctx context.Context) error {
|
|
_, err := q.db.Exec(ctx, DeleteAllVirtualGameProviders)
|
|
return err
|
|
}
|
|
|
|
const DeleteVirtualGameProvider = `-- name: DeleteVirtualGameProvider :exec
|
|
DELETE FROM virtual_game_providers
|
|
WHERE provider_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteVirtualGameProvider(ctx context.Context, providerID string) error {
|
|
_, err := q.db.Exec(ctx, DeleteVirtualGameProvider, providerID)
|
|
return err
|
|
}
|
|
|
|
const GetVirtualGameProviderByID = `-- name: GetVirtualGameProviderByID :one
|
|
SELECT id, provider_id, provider_name, logo_dark, logo_light, enabled, created_at, updated_at
|
|
FROM virtual_game_providers
|
|
WHERE provider_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetVirtualGameProviderByID(ctx context.Context, providerID string) (VirtualGameProvider, error) {
|
|
row := q.db.QueryRow(ctx, GetVirtualGameProviderByID, providerID)
|
|
var i VirtualGameProvider
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProviderID,
|
|
&i.ProviderName,
|
|
&i.LogoDark,
|
|
&i.LogoLight,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetVirtualGameSessionByToken = `-- name: GetVirtualGameSessionByToken :one
|
|
SELECT id, user_id, game_id, session_token, currency, status, created_at, updated_at, expires_at
|
|
FROM virtual_game_sessions
|
|
WHERE session_token = $1
|
|
`
|
|
|
|
func (q *Queries) GetVirtualGameSessionByToken(ctx context.Context, sessionToken string) (VirtualGameSession, error) {
|
|
row := q.db.QueryRow(ctx, GetVirtualGameSessionByToken, sessionToken)
|
|
var i VirtualGameSession
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.GameID,
|
|
&i.SessionToken,
|
|
&i.Currency,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.ExpiresAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetVirtualGameSummaryInRange = `-- name: GetVirtualGameSummaryInRange :many
|
|
SELECT
|
|
c.name AS company_name,
|
|
vg.name AS game_name,
|
|
COUNT(vgt.id) AS number_of_bets,
|
|
COALESCE(SUM(vgt.amount), 0) AS total_transaction_sum
|
|
FROM virtual_game_transactions vgt
|
|
JOIN virtual_game_sessions vgs ON vgt.session_id = vgs.id
|
|
JOIN virtual_games vg ON vgs.game_id = vg.id
|
|
JOIN companies c ON vgt.company_id = c.id
|
|
WHERE vgt.transaction_type = 'BET'
|
|
AND vgt.created_at BETWEEN $1 AND $2
|
|
GROUP BY c.name, vg.name
|
|
`
|
|
|
|
type GetVirtualGameSummaryInRangeParams struct {
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
CreatedAt_2 pgtype.Timestamptz `json:"created_at_2"`
|
|
}
|
|
|
|
type GetVirtualGameSummaryInRangeRow struct {
|
|
CompanyName string `json:"company_name"`
|
|
GameName string `json:"game_name"`
|
|
NumberOfBets int64 `json:"number_of_bets"`
|
|
TotalTransactionSum interface{} `json:"total_transaction_sum"`
|
|
}
|
|
|
|
func (q *Queries) GetVirtualGameSummaryInRange(ctx context.Context, arg GetVirtualGameSummaryInRangeParams) ([]GetVirtualGameSummaryInRangeRow, error) {
|
|
rows, err := q.db.Query(ctx, GetVirtualGameSummaryInRange, arg.CreatedAt, arg.CreatedAt_2)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetVirtualGameSummaryInRangeRow
|
|
for rows.Next() {
|
|
var i GetVirtualGameSummaryInRangeRow
|
|
if err := rows.Scan(
|
|
&i.CompanyName,
|
|
&i.GameName,
|
|
&i.NumberOfBets,
|
|
&i.TotalTransactionSum,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetVirtualGameTransactionByExternalID = `-- name: GetVirtualGameTransactionByExternalID :one
|
|
SELECT id, session_id, user_id, wallet_id, transaction_type, amount, currency, external_transaction_id, status, created_at, updated_at
|
|
FROM virtual_game_transactions
|
|
WHERE external_transaction_id = $1
|
|
`
|
|
|
|
type GetVirtualGameTransactionByExternalIDRow struct {
|
|
ID int64 `json:"id"`
|
|
SessionID int64 `json:"session_id"`
|
|
UserID int64 `json:"user_id"`
|
|
WalletID int64 `json:"wallet_id"`
|
|
TransactionType string `json:"transaction_type"`
|
|
Amount int64 `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
ExternalTransactionID string `json:"external_transaction_id"`
|
|
Status string `json:"status"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) GetVirtualGameTransactionByExternalID(ctx context.Context, externalTransactionID string) (GetVirtualGameTransactionByExternalIDRow, error) {
|
|
row := q.db.QueryRow(ctx, GetVirtualGameTransactionByExternalID, externalTransactionID)
|
|
var i GetVirtualGameTransactionByExternalIDRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.SessionID,
|
|
&i.UserID,
|
|
&i.WalletID,
|
|
&i.TransactionType,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.ExternalTransactionID,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const ListFavoriteGames = `-- name: ListFavoriteGames :many
|
|
SELECT game_id
|
|
FROM favorite_games
|
|
WHERE user_id = $1
|
|
`
|
|
|
|
func (q *Queries) ListFavoriteGames(ctx context.Context, userID int64) ([]int64, error) {
|
|
rows, err := q.db.Query(ctx, ListFavoriteGames, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []int64
|
|
for rows.Next() {
|
|
var game_id int64
|
|
if err := rows.Scan(&game_id); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, game_id)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const ListVirtualGameProviders = `-- name: ListVirtualGameProviders :many
|
|
SELECT id, provider_id, provider_name, logo_dark, logo_light, enabled, created_at, updated_at
|
|
FROM virtual_game_providers
|
|
ORDER BY created_at DESC
|
|
LIMIT $1 OFFSET $2
|
|
`
|
|
|
|
type ListVirtualGameProvidersParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListVirtualGameProviders(ctx context.Context, arg ListVirtualGameProvidersParams) ([]VirtualGameProvider, error) {
|
|
rows, err := q.db.Query(ctx, ListVirtualGameProviders, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []VirtualGameProvider
|
|
for rows.Next() {
|
|
var i VirtualGameProvider
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ProviderID,
|
|
&i.ProviderName,
|
|
&i.LogoDark,
|
|
&i.LogoLight,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const RemoveFavoriteGame = `-- name: RemoveFavoriteGame :exec
|
|
DELETE FROM favorite_games
|
|
WHERE user_id = $1 AND game_id = $2
|
|
`
|
|
|
|
type RemoveFavoriteGameParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
GameID int64 `json:"game_id"`
|
|
}
|
|
|
|
func (q *Queries) RemoveFavoriteGame(ctx context.Context, arg RemoveFavoriteGameParams) error {
|
|
_, err := q.db.Exec(ctx, RemoveFavoriteGame, arg.UserID, arg.GameID)
|
|
return err
|
|
}
|
|
|
|
const UpdateVirtualGameProviderEnabled = `-- name: UpdateVirtualGameProviderEnabled :one
|
|
UPDATE virtual_game_providers
|
|
SET enabled = $2,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE provider_id = $1
|
|
RETURNING id, provider_id, provider_name, logo_dark, logo_light, enabled, created_at, updated_at
|
|
`
|
|
|
|
type UpdateVirtualGameProviderEnabledParams struct {
|
|
ProviderID string `json:"provider_id"`
|
|
Enabled bool `json:"enabled"`
|
|
}
|
|
|
|
func (q *Queries) UpdateVirtualGameProviderEnabled(ctx context.Context, arg UpdateVirtualGameProviderEnabledParams) (VirtualGameProvider, error) {
|
|
row := q.db.QueryRow(ctx, UpdateVirtualGameProviderEnabled, arg.ProviderID, arg.Enabled)
|
|
var i VirtualGameProvider
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProviderID,
|
|
&i.ProviderName,
|
|
&i.LogoDark,
|
|
&i.LogoLight,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const UpdateVirtualGameSessionStatus = `-- name: UpdateVirtualGameSessionStatus :exec
|
|
UPDATE virtual_game_sessions
|
|
SET status = $2, updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateVirtualGameSessionStatusParams struct {
|
|
ID int64 `json:"id"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
func (q *Queries) UpdateVirtualGameSessionStatus(ctx context.Context, arg UpdateVirtualGameSessionStatusParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateVirtualGameSessionStatus, arg.ID, arg.Status)
|
|
return err
|
|
}
|
|
|
|
const UpdateVirtualGameTransactionStatus = `-- name: UpdateVirtualGameTransactionStatus :exec
|
|
UPDATE virtual_game_transactions
|
|
SET status = $2, updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateVirtualGameTransactionStatusParams struct {
|
|
ID int64 `json:"id"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
func (q *Queries) UpdateVirtualGameTransactionStatus(ctx context.Context, arg UpdateVirtualGameTransactionStatusParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateVirtualGameTransactionStatus, arg.ID, arg.Status)
|
|
return err
|
|
}
|