294 lines
6.8 KiB
Go
294 lines
6.8 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 company_league_settings
|
|
WHERE league_id = $1
|
|
AND company_id = $2
|
|
AND is_active = true
|
|
)
|
|
`
|
|
|
|
type CheckLeagueSupportParams struct {
|
|
LeagueID int64 `json:"league_id"`
|
|
CompanyID int64 `json:"company_id"`
|
|
}
|
|
|
|
func (q *Queries) CheckLeagueSupport(ctx context.Context, arg CheckLeagueSupportParams) (bool, error) {
|
|
row := q.db.QueryRow(ctx, CheckLeagueSupport, arg.LeagueID, arg.CompanyID)
|
|
var exists bool
|
|
err := row.Scan(&exists)
|
|
return exists, err
|
|
}
|
|
|
|
const GetAllLeagues = `-- name: GetAllLeagues :many
|
|
SELECT id, name, img_url, country_code, bet365_id, sport_id, default_is_active, default_is_featured
|
|
FROM leagues
|
|
WHERE (
|
|
country_code = $1
|
|
OR $1 IS NULL
|
|
)
|
|
AND (
|
|
sport_id = $2
|
|
OR $2 IS NULL
|
|
)
|
|
ORDER BY name ASC
|
|
LIMIT $4 OFFSET $3
|
|
`
|
|
|
|
type GetAllLeaguesParams struct {
|
|
CountryCode pgtype.Text `json:"country_code"`
|
|
SportID pgtype.Int4 `json:"sport_id"`
|
|
Offset pgtype.Int4 `json:"offset"`
|
|
Limit pgtype.Int4 `json:"limit"`
|
|
}
|
|
|
|
func (q *Queries) GetAllLeagues(ctx context.Context, arg GetAllLeaguesParams) ([]League, error) {
|
|
rows, err := q.db.Query(ctx, GetAllLeagues,
|
|
arg.CountryCode,
|
|
arg.SportID,
|
|
arg.Offset,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []League
|
|
for rows.Next() {
|
|
var i League
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.ImgUrl,
|
|
&i.CountryCode,
|
|
&i.Bet365ID,
|
|
&i.SportID,
|
|
&i.DefaultIsActive,
|
|
&i.DefaultIsFeatured,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetAllLeaguesWithSettings = `-- name: GetAllLeaguesWithSettings :many
|
|
SELECT id, name, img_url, country_code, bet365_id, sport_id, default_is_active, default_is_featured, company_id, is_active, is_featured, updated_at
|
|
FROM league_with_settings
|
|
WHERE (company_id = $1)
|
|
AND (
|
|
country_code = $2
|
|
OR $2 IS NULL
|
|
)
|
|
AND (
|
|
sport_id = $3
|
|
OR $3 IS NULL
|
|
)
|
|
AND (
|
|
is_active = $4
|
|
OR $4 IS NULL
|
|
)
|
|
AND (
|
|
is_featured = $5
|
|
OR $5 IS NULL
|
|
)
|
|
ORDER BY is_featured DESC,
|
|
name ASC
|
|
LIMIT $7 OFFSET $6
|
|
`
|
|
|
|
type GetAllLeaguesWithSettingsParams struct {
|
|
CompanyID int64 `json:"company_id"`
|
|
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"`
|
|
}
|
|
|
|
func (q *Queries) GetAllLeaguesWithSettings(ctx context.Context, arg GetAllLeaguesWithSettingsParams) ([]LeagueWithSetting, error) {
|
|
rows, err := q.db.Query(ctx, GetAllLeaguesWithSettings,
|
|
arg.CompanyID,
|
|
arg.CountryCode,
|
|
arg.SportID,
|
|
arg.IsActive,
|
|
arg.IsFeatured,
|
|
arg.Offset,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []LeagueWithSetting
|
|
for rows.Next() {
|
|
var i LeagueWithSetting
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.ImgUrl,
|
|
&i.CountryCode,
|
|
&i.Bet365ID,
|
|
&i.SportID,
|
|
&i.DefaultIsActive,
|
|
&i.DefaultIsFeatured,
|
|
&i.CompanyID,
|
|
&i.IsActive,
|
|
&i.IsFeatured,
|
|
&i.UpdatedAt,
|
|
); 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,
|
|
default_is_active,
|
|
default_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,
|
|
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"`
|
|
DefaultIsActive bool `json:"default_is_active"`
|
|
DefaultIsFeatured bool `json:"default_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.DefaultIsActive,
|
|
arg.DefaultIsFeatured,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const InsertLeagueSettings = `-- name: InsertLeagueSettings :exec
|
|
INSERT INTO company_league_settings (
|
|
company_id,
|
|
league_id,
|
|
is_active,
|
|
is_featured
|
|
)
|
|
VALUES ($1, $2, $3, $4) ON CONFLICT(company_id, league_id) DO
|
|
UPDATE
|
|
SET is_active = EXCLUDED.is_active,
|
|
is_featured = EXCLUDED.is_featured
|
|
`
|
|
|
|
type InsertLeagueSettingsParams struct {
|
|
CompanyID int64 `json:"company_id"`
|
|
LeagueID int64 `json:"league_id"`
|
|
IsActive pgtype.Bool `json:"is_active"`
|
|
IsFeatured pgtype.Bool `json:"is_featured"`
|
|
}
|
|
|
|
func (q *Queries) InsertLeagueSettings(ctx context.Context, arg InsertLeagueSettingsParams) error {
|
|
_, err := q.db.Exec(ctx, InsertLeagueSettings,
|
|
arg.CompanyID,
|
|
arg.LeagueID,
|
|
arg.IsActive,
|
|
arg.IsFeatured,
|
|
)
|
|
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),
|
|
sport_id = COALESCE($5, 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"`
|
|
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.SportID,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const UpdateLeagueSettings = `-- name: UpdateLeagueSettings :exec
|
|
UPDATE company_league_settings
|
|
SET is_active = COALESCE($3, is_active),
|
|
is_featured = COALESCE(
|
|
$4,
|
|
is_featured
|
|
)
|
|
WHERE league_id = $1
|
|
AND company_id = $2
|
|
`
|
|
|
|
type UpdateLeagueSettingsParams struct {
|
|
LeagueID int64 `json:"league_id"`
|
|
CompanyID int64 `json:"company_id"`
|
|
IsActive pgtype.Bool `json:"is_active"`
|
|
IsFeatured pgtype.Bool `json:"is_featured"`
|
|
}
|
|
|
|
func (q *Queries) UpdateLeagueSettings(ctx context.Context, arg UpdateLeagueSettingsParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateLeagueSettings,
|
|
arg.LeagueID,
|
|
arg.CompanyID,
|
|
arg.IsActive,
|
|
arg.IsFeatured,
|
|
)
|
|
return err
|
|
}
|