290 lines
6.6 KiB
Go
290 lines
6.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: leagues.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const CheckLeagueSupport = `-- name: CheckLeagueSupport :one
|
|
SELECT EXISTS(
|
|
SELECT 1
|
|
FROM leagues
|
|
WHERE id = $1
|
|
AND is_active = true
|
|
)
|
|
`
|
|
|
|
func (q *Queries) CheckLeagueSupport(ctx context.Context, id int64) (bool, error) {
|
|
row := q.db.QueryRow(ctx, CheckLeagueSupport, id)
|
|
var exists bool
|
|
err := row.Scan(&exists)
|
|
return exists, err
|
|
}
|
|
|
|
const GetAllLeagues = `-- name: GetAllLeagues :many
|
|
SELECT id,
|
|
name,
|
|
country_code,
|
|
bet365_id,
|
|
is_active,
|
|
is_featured,
|
|
sport_id
|
|
FROM leagues
|
|
WHERE (
|
|
country_code = $1
|
|
OR $1 IS NULL
|
|
)
|
|
AND (
|
|
sport_id = $2
|
|
OR $2 IS NULL
|
|
)
|
|
AND (
|
|
is_active = $3
|
|
OR $3 IS NULL
|
|
)
|
|
AND (
|
|
is_featured = $4
|
|
OR $4 IS NULL
|
|
)
|
|
ORDER BY is_featured DESC,
|
|
name ASC
|
|
LIMIT $6 OFFSET $5
|
|
`
|
|
|
|
type GetAllLeaguesParams struct {
|
|
CountryCode pgtype.Text `json:"country_code"`
|
|
SportID pgtype.Int4 `json:"sport_id"`
|
|
IsActive pgtype.Bool `json:"is_active"`
|
|
IsFeatured pgtype.Bool `json:"is_featured"`
|
|
Offset pgtype.Int4 `json:"offset"`
|
|
Limit pgtype.Int4 `json:"limit"`
|
|
}
|
|
|
|
type GetAllLeaguesRow struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
CountryCode pgtype.Text `json:"country_code"`
|
|
Bet365ID pgtype.Int4 `json:"bet365_id"`
|
|
IsActive pgtype.Bool `json:"is_active"`
|
|
IsFeatured pgtype.Bool `json:"is_featured"`
|
|
SportID int32 `json:"sport_id"`
|
|
}
|
|
|
|
func (q *Queries) GetAllLeagues(ctx context.Context, arg GetAllLeaguesParams) ([]GetAllLeaguesRow, error) {
|
|
rows, err := q.db.Query(ctx, GetAllLeagues,
|
|
arg.CountryCode,
|
|
arg.SportID,
|
|
arg.IsActive,
|
|
arg.IsFeatured,
|
|
arg.Offset,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetAllLeaguesRow
|
|
for rows.Next() {
|
|
var i GetAllLeaguesRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.CountryCode,
|
|
&i.Bet365ID,
|
|
&i.IsActive,
|
|
&i.IsFeatured,
|
|
&i.SportID,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetFeaturedLeagues = `-- name: GetFeaturedLeagues :many
|
|
SELECT id,
|
|
name,
|
|
country_code,
|
|
bet365_id,
|
|
is_active,
|
|
is_featured,
|
|
sport_id
|
|
FROM leagues
|
|
WHERE is_featured = true
|
|
`
|
|
|
|
type GetFeaturedLeaguesRow struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
CountryCode pgtype.Text `json:"country_code"`
|
|
Bet365ID pgtype.Int4 `json:"bet365_id"`
|
|
IsActive pgtype.Bool `json:"is_active"`
|
|
IsFeatured pgtype.Bool `json:"is_featured"`
|
|
SportID int32 `json:"sport_id"`
|
|
}
|
|
|
|
func (q *Queries) GetFeaturedLeagues(ctx context.Context) ([]GetFeaturedLeaguesRow, error) {
|
|
rows, err := q.db.Query(ctx, GetFeaturedLeagues)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetFeaturedLeaguesRow
|
|
for rows.Next() {
|
|
var i GetFeaturedLeaguesRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.CountryCode,
|
|
&i.Bet365ID,
|
|
&i.IsActive,
|
|
&i.IsFeatured,
|
|
&i.SportID,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const InsertLeague = `-- name: InsertLeague :exec
|
|
INSERT INTO leagues (
|
|
id,
|
|
name,
|
|
country_code,
|
|
bet365_id,
|
|
sport_id,
|
|
is_active,
|
|
is_featured
|
|
)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7) ON CONFLICT (id) DO
|
|
UPDATE
|
|
SET name = EXCLUDED.name,
|
|
country_code = EXCLUDED.country_code,
|
|
bet365_id = EXCLUDED.bet365_id,
|
|
is_active = EXCLUDED.is_active,
|
|
is_featured = EXCLUDED.is_featured,
|
|
sport_id = EXCLUDED.sport_id
|
|
`
|
|
|
|
type InsertLeagueParams struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
CountryCode pgtype.Text `json:"country_code"`
|
|
Bet365ID pgtype.Int4 `json:"bet365_id"`
|
|
SportID int32 `json:"sport_id"`
|
|
IsActive pgtype.Bool `json:"is_active"`
|
|
IsFeatured pgtype.Bool `json:"is_featured"`
|
|
}
|
|
|
|
func (q *Queries) InsertLeague(ctx context.Context, arg InsertLeagueParams) error {
|
|
_, err := q.db.Exec(ctx, InsertLeague,
|
|
arg.ID,
|
|
arg.Name,
|
|
arg.CountryCode,
|
|
arg.Bet365ID,
|
|
arg.SportID,
|
|
arg.IsActive,
|
|
arg.IsFeatured,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const SetLeagueActive = `-- name: SetLeagueActive :exec
|
|
UPDATE leagues
|
|
SET is_active = $2
|
|
WHERE id = $1
|
|
`
|
|
|
|
type SetLeagueActiveParams struct {
|
|
ID int64 `json:"id"`
|
|
IsActive pgtype.Bool `json:"is_active"`
|
|
}
|
|
|
|
func (q *Queries) SetLeagueActive(ctx context.Context, arg SetLeagueActiveParams) error {
|
|
_, err := q.db.Exec(ctx, SetLeagueActive, arg.ID, arg.IsActive)
|
|
return err
|
|
}
|
|
|
|
const UpdateLeague = `-- name: UpdateLeague :exec
|
|
UPDATE leagues
|
|
SET name = COALESCE($2, name),
|
|
country_code = COALESCE($3, country_code),
|
|
bet365_id = COALESCE($4, bet365_id),
|
|
is_active = COALESCE($5, is_active),
|
|
is_featured = COALESCE($6, is_featured),
|
|
sport_id = COALESCE($7, sport_id)
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateLeagueParams struct {
|
|
ID int64 `json:"id"`
|
|
Name pgtype.Text `json:"name"`
|
|
CountryCode pgtype.Text `json:"country_code"`
|
|
Bet365ID pgtype.Int4 `json:"bet365_id"`
|
|
IsActive pgtype.Bool `json:"is_active"`
|
|
IsFeatured pgtype.Bool `json:"is_featured"`
|
|
SportID pgtype.Int4 `json:"sport_id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateLeague(ctx context.Context, arg UpdateLeagueParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateLeague,
|
|
arg.ID,
|
|
arg.Name,
|
|
arg.CountryCode,
|
|
arg.Bet365ID,
|
|
arg.IsActive,
|
|
arg.IsFeatured,
|
|
arg.SportID,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const UpdateLeagueByBet365ID = `-- name: UpdateLeagueByBet365ID :exec
|
|
UPDATE leagues
|
|
SET name = COALESCE($2, name),
|
|
id = COALESCE($3, id),
|
|
country_code = COALESCE($4, country_code),
|
|
is_active = COALESCE($5, is_active),
|
|
is_featured = COALESCE($6, is_featured),
|
|
sport_id = COALESCE($7, sport_id)
|
|
WHERE bet365_id = $1
|
|
`
|
|
|
|
type UpdateLeagueByBet365IDParams struct {
|
|
Bet365ID pgtype.Int4 `json:"bet365_id"`
|
|
Name pgtype.Text `json:"name"`
|
|
ID pgtype.Int8 `json:"id"`
|
|
CountryCode pgtype.Text `json:"country_code"`
|
|
IsActive pgtype.Bool `json:"is_active"`
|
|
IsFeatured pgtype.Bool `json:"is_featured"`
|
|
SportID pgtype.Int4 `json:"sport_id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateLeagueByBet365ID(ctx context.Context, arg UpdateLeagueByBet365IDParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateLeagueByBet365ID,
|
|
arg.Bet365ID,
|
|
arg.Name,
|
|
arg.ID,
|
|
arg.CountryCode,
|
|
arg.IsActive,
|
|
arg.IsFeatured,
|
|
arg.SportID,
|
|
)
|
|
return err
|
|
}
|