517 lines
13 KiB
Go
517 lines
13 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.25.0
|
|
// source: batch.go
|
|
|
|
package model
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
var (
|
|
ErrBatchAlreadyClosed = errors.New("batch already closed")
|
|
)
|
|
|
|
const createOrUpdateCompetitions = `-- name: CreateOrUpdateCompetitions :batchexec
|
|
INSERT INTO competitions (
|
|
slug,
|
|
display_name,
|
|
country_slug,
|
|
competition_format,
|
|
competition_type,
|
|
picture_url,
|
|
logo_url
|
|
)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7) ON CONFLICT (slug)
|
|
DO
|
|
UPDATE
|
|
SET display_name = EXCLUDED.display_name,
|
|
competition_format = EXCLUDED.competition_format,
|
|
competition_type = EXCLUDED.competition_type,
|
|
picture_url = EXCLUDED.picture_url,
|
|
logo_url = EXCLUDED.logo_url,
|
|
country_slug = EXCLUDED.country_slug
|
|
`
|
|
|
|
type CreateOrUpdateCompetitionsBatchResults struct {
|
|
br pgx.BatchResults
|
|
tot int
|
|
closed bool
|
|
}
|
|
|
|
type CreateOrUpdateCompetitionsParams struct {
|
|
Slug string
|
|
DisplayName string
|
|
CountrySlug string
|
|
CompetitionFormat string
|
|
CompetitionType string
|
|
PictureUrl string
|
|
LogoUrl string
|
|
}
|
|
|
|
func (q *Queries) CreateOrUpdateCompetitions(ctx context.Context, arg []CreateOrUpdateCompetitionsParams) *CreateOrUpdateCompetitionsBatchResults {
|
|
batch := &pgx.Batch{}
|
|
for _, a := range arg {
|
|
vals := []interface{}{
|
|
a.Slug,
|
|
a.DisplayName,
|
|
a.CountrySlug,
|
|
a.CompetitionFormat,
|
|
a.CompetitionType,
|
|
a.PictureUrl,
|
|
a.LogoUrl,
|
|
}
|
|
batch.Queue(createOrUpdateCompetitions, vals...)
|
|
}
|
|
br := q.db.SendBatch(ctx, batch)
|
|
return &CreateOrUpdateCompetitionsBatchResults{br, len(arg), false}
|
|
}
|
|
|
|
func (b *CreateOrUpdateCompetitionsBatchResults) Exec(f func(int, error)) {
|
|
defer b.br.Close()
|
|
for t := 0; t < b.tot; t++ {
|
|
if b.closed {
|
|
if f != nil {
|
|
f(t, ErrBatchAlreadyClosed)
|
|
}
|
|
continue
|
|
}
|
|
_, err := b.br.Exec()
|
|
if f != nil {
|
|
f(t, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (b *CreateOrUpdateCompetitionsBatchResults) Close() error {
|
|
b.closed = true
|
|
return b.br.Close()
|
|
}
|
|
|
|
const createOrUpdateCountries = `-- name: CreateOrUpdateCountries :batchexec
|
|
INSERT INTO countries (
|
|
slug,
|
|
code,
|
|
display_name,
|
|
three_letter_code,
|
|
flag_flat_64_url,
|
|
flag_flat_32_url,
|
|
flag_round_64_url,
|
|
flag_round_32_url
|
|
)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
|
ON CONFLICT (slug)
|
|
DO UPDATE
|
|
SET code = EXCLUDED.code,
|
|
display_name = EXCLUDED.display_name,
|
|
three_letter_code = EXCLUDED.three_letter_code,
|
|
flag_flat_64_url = EXCLUDED.flag_flat_64_url,
|
|
flag_flat_32_url = EXCLUDED.flag_flat_32_url,
|
|
flag_round_64_url = EXCLUDED.flag_round_64_url,
|
|
flag_round_32_url = EXCLUDED.flag_round_32_url
|
|
`
|
|
|
|
type CreateOrUpdateCountriesBatchResults struct {
|
|
br pgx.BatchResults
|
|
tot int
|
|
closed bool
|
|
}
|
|
|
|
type CreateOrUpdateCountriesParams struct {
|
|
Slug string
|
|
Code string
|
|
DisplayName string
|
|
ThreeLetterCode string
|
|
FlagFlat64Url string
|
|
FlagFlat32Url string
|
|
FlagRound64Url string
|
|
FlagRound32Url string
|
|
}
|
|
|
|
func (q *Queries) CreateOrUpdateCountries(ctx context.Context, arg []CreateOrUpdateCountriesParams) *CreateOrUpdateCountriesBatchResults {
|
|
batch := &pgx.Batch{}
|
|
for _, a := range arg {
|
|
vals := []interface{}{
|
|
a.Slug,
|
|
a.Code,
|
|
a.DisplayName,
|
|
a.ThreeLetterCode,
|
|
a.FlagFlat64Url,
|
|
a.FlagFlat32Url,
|
|
a.FlagRound64Url,
|
|
a.FlagRound32Url,
|
|
}
|
|
batch.Queue(createOrUpdateCountries, vals...)
|
|
}
|
|
br := q.db.SendBatch(ctx, batch)
|
|
return &CreateOrUpdateCountriesBatchResults{br, len(arg), false}
|
|
}
|
|
|
|
func (b *CreateOrUpdateCountriesBatchResults) Exec(f func(int, error)) {
|
|
defer b.br.Close()
|
|
for t := 0; t < b.tot; t++ {
|
|
if b.closed {
|
|
if f != nil {
|
|
f(t, ErrBatchAlreadyClosed)
|
|
}
|
|
continue
|
|
}
|
|
_, err := b.br.Exec()
|
|
if f != nil {
|
|
f(t, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (b *CreateOrUpdateCountriesBatchResults) Close() error {
|
|
b.closed = true
|
|
return b.br.Close()
|
|
}
|
|
|
|
const createOrUpdateFixtures = `-- name: CreateOrUpdateFixtures :batchexec
|
|
INSERT INTO fixtures (slug, display_name, state, start_date, end_date, game_week)
|
|
VALUES ($1, $2, $3, $4, $5, $6)
|
|
ON CONFLICT (slug) DO UPDATE
|
|
SET display_name = $2, state = $3, start_date = $4, end_date = $5, game_week = $6
|
|
`
|
|
|
|
type CreateOrUpdateFixturesBatchResults struct {
|
|
br pgx.BatchResults
|
|
tot int
|
|
closed bool
|
|
}
|
|
|
|
type CreateOrUpdateFixturesParams struct {
|
|
Slug string
|
|
DisplayName string
|
|
State string
|
|
StartDate pgtype.Timestamptz
|
|
EndDate pgtype.Timestamptz
|
|
GameWeek int32
|
|
}
|
|
|
|
func (q *Queries) CreateOrUpdateFixtures(ctx context.Context, arg []CreateOrUpdateFixturesParams) *CreateOrUpdateFixturesBatchResults {
|
|
batch := &pgx.Batch{}
|
|
for _, a := range arg {
|
|
vals := []interface{}{
|
|
a.Slug,
|
|
a.DisplayName,
|
|
a.State,
|
|
a.StartDate,
|
|
a.EndDate,
|
|
a.GameWeek,
|
|
}
|
|
batch.Queue(createOrUpdateFixtures, vals...)
|
|
}
|
|
br := q.db.SendBatch(ctx, batch)
|
|
return &CreateOrUpdateFixturesBatchResults{br, len(arg), false}
|
|
}
|
|
|
|
func (b *CreateOrUpdateFixturesBatchResults) Exec(f func(int, error)) {
|
|
defer b.br.Close()
|
|
for t := 0; t < b.tot; t++ {
|
|
if b.closed {
|
|
if f != nil {
|
|
f(t, ErrBatchAlreadyClosed)
|
|
}
|
|
continue
|
|
}
|
|
_, err := b.br.Exec()
|
|
if f != nil {
|
|
f(t, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (b *CreateOrUpdateFixturesBatchResults) Close() error {
|
|
b.closed = true
|
|
return b.br.Close()
|
|
}
|
|
|
|
const createOrUpdateGamePlayers = `-- name: CreateOrUpdateGamePlayers :batchexec
|
|
INSERT INTO game_players(
|
|
game_id,
|
|
player_slug,
|
|
status,
|
|
team_slug)
|
|
VALUES(
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4)
|
|
ON CONFLICT (game_id, player_slug) DO UPDATE
|
|
SET status = $3,
|
|
team_slug = $4
|
|
`
|
|
|
|
type CreateOrUpdateGamePlayersBatchResults struct {
|
|
br pgx.BatchResults
|
|
tot int
|
|
closed bool
|
|
}
|
|
|
|
type CreateOrUpdateGamePlayersParams struct {
|
|
GameID string
|
|
PlayerSlug string
|
|
Status string
|
|
TeamSlug string
|
|
}
|
|
|
|
func (q *Queries) CreateOrUpdateGamePlayers(ctx context.Context, arg []CreateOrUpdateGamePlayersParams) *CreateOrUpdateGamePlayersBatchResults {
|
|
batch := &pgx.Batch{}
|
|
for _, a := range arg {
|
|
vals := []interface{}{
|
|
a.GameID,
|
|
a.PlayerSlug,
|
|
a.Status,
|
|
a.TeamSlug,
|
|
}
|
|
batch.Queue(createOrUpdateGamePlayers, vals...)
|
|
}
|
|
br := q.db.SendBatch(ctx, batch)
|
|
return &CreateOrUpdateGamePlayersBatchResults{br, len(arg), false}
|
|
}
|
|
|
|
func (b *CreateOrUpdateGamePlayersBatchResults) Exec(f func(int, error)) {
|
|
defer b.br.Close()
|
|
for t := 0; t < b.tot; t++ {
|
|
if b.closed {
|
|
if f != nil {
|
|
f(t, ErrBatchAlreadyClosed)
|
|
}
|
|
continue
|
|
}
|
|
_, err := b.br.Exec()
|
|
if f != nil {
|
|
f(t, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (b *CreateOrUpdateGamePlayersBatchResults) Close() error {
|
|
b.closed = true
|
|
return b.br.Close()
|
|
}
|
|
|
|
const createOrUpdateGames = `-- name: CreateOrUpdateGames :batchexec
|
|
INSERT INTO games (id, date, coverage_status, low_coverage, minutes, period_type, scored, status, competition_slug, fixture_slug, away_team_slug, away_goals, away_extra_time_score, away_penalty_score, home_team_slug, home_goals, home_extra_time_score, home_penalty_score, winner_team_slug)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19)
|
|
ON CONFLICT (id) DO UPDATE
|
|
SET date = EXCLUDED.date, coverage_status = EXCLUDED.coverage_status, low_coverage = EXCLUDED.low_coverage, minutes = EXCLUDED.minutes, period_type = EXCLUDED.period_type, scored = EXCLUDED.scored, status = EXCLUDED.status, competition_slug = EXCLUDED.competition_slug, fixture_slug = EXCLUDED.fixture_slug, away_team_slug = EXCLUDED.away_team_slug, away_goals = EXCLUDED.away_goals, away_extra_time_score = EXCLUDED.away_extra_time_score, away_penalty_score = EXCLUDED.away_penalty_score, home_team_slug = EXCLUDED.home_team_slug, home_goals = EXCLUDED.home_goals, home_extra_time_score = EXCLUDED.home_extra_time_score, home_penalty_score = EXCLUDED.home_penalty_score, winner_team_slug = EXCLUDED.winner_team_slug
|
|
`
|
|
|
|
type CreateOrUpdateGamesBatchResults struct {
|
|
br pgx.BatchResults
|
|
tot int
|
|
closed bool
|
|
}
|
|
|
|
type CreateOrUpdateGamesParams struct {
|
|
ID string
|
|
Date pgtype.Timestamptz
|
|
CoverageStatus string
|
|
LowCoverage bool
|
|
Minutes int32
|
|
PeriodType string
|
|
Scored bool
|
|
Status string
|
|
CompetitionSlug string
|
|
FixtureSlug string
|
|
AwayTeamSlug string
|
|
AwayGoals int32
|
|
AwayExtraTimeScore int32
|
|
AwayPenaltyScore int32
|
|
HomeTeamSlug string
|
|
HomeGoals int32
|
|
HomeExtraTimeScore int32
|
|
HomePenaltyScore int32
|
|
WinnerTeamSlug *string
|
|
}
|
|
|
|
func (q *Queries) CreateOrUpdateGames(ctx context.Context, arg []CreateOrUpdateGamesParams) *CreateOrUpdateGamesBatchResults {
|
|
batch := &pgx.Batch{}
|
|
for _, a := range arg {
|
|
vals := []interface{}{
|
|
a.ID,
|
|
a.Date,
|
|
a.CoverageStatus,
|
|
a.LowCoverage,
|
|
a.Minutes,
|
|
a.PeriodType,
|
|
a.Scored,
|
|
a.Status,
|
|
a.CompetitionSlug,
|
|
a.FixtureSlug,
|
|
a.AwayTeamSlug,
|
|
a.AwayGoals,
|
|
a.AwayExtraTimeScore,
|
|
a.AwayPenaltyScore,
|
|
a.HomeTeamSlug,
|
|
a.HomeGoals,
|
|
a.HomeExtraTimeScore,
|
|
a.HomePenaltyScore,
|
|
a.WinnerTeamSlug,
|
|
}
|
|
batch.Queue(createOrUpdateGames, vals...)
|
|
}
|
|
br := q.db.SendBatch(ctx, batch)
|
|
return &CreateOrUpdateGamesBatchResults{br, len(arg), false}
|
|
}
|
|
|
|
func (b *CreateOrUpdateGamesBatchResults) Exec(f func(int, error)) {
|
|
defer b.br.Close()
|
|
for t := 0; t < b.tot; t++ {
|
|
if b.closed {
|
|
if f != nil {
|
|
f(t, ErrBatchAlreadyClosed)
|
|
}
|
|
continue
|
|
}
|
|
_, err := b.br.Exec()
|
|
if f != nil {
|
|
f(t, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (b *CreateOrUpdateGamesBatchResults) Close() error {
|
|
b.closed = true
|
|
return b.br.Close()
|
|
}
|
|
|
|
const createOrUpdatePlayers = `-- name: CreateOrUpdatePlayers :batchexec
|
|
INSERT INTO players (slug, display_name, birth_date, country_slug, team_slug, domestic_league_slug, avatar_url, field_position, status, shirt_number)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
|
ON CONFLICT (slug) DO UPDATE
|
|
SET display_name = $2, birth_date = $3, country_slug = $4, team_slug = $5, domestic_league_slug = $6, avatar_url = $7, field_position = $8, status = $9, shirt_number = $10
|
|
`
|
|
|
|
type CreateOrUpdatePlayersBatchResults struct {
|
|
br pgx.BatchResults
|
|
tot int
|
|
closed bool
|
|
}
|
|
|
|
type CreateOrUpdatePlayersParams struct {
|
|
Slug string
|
|
DisplayName string
|
|
BirthDate time.Time
|
|
CountrySlug string
|
|
TeamSlug *string
|
|
DomesticLeagueSlug *string
|
|
AvatarUrl string
|
|
FieldPosition string
|
|
Status string
|
|
ShirtNumber int32
|
|
}
|
|
|
|
func (q *Queries) CreateOrUpdatePlayers(ctx context.Context, arg []CreateOrUpdatePlayersParams) *CreateOrUpdatePlayersBatchResults {
|
|
batch := &pgx.Batch{}
|
|
for _, a := range arg {
|
|
vals := []interface{}{
|
|
a.Slug,
|
|
a.DisplayName,
|
|
a.BirthDate,
|
|
a.CountrySlug,
|
|
a.TeamSlug,
|
|
a.DomesticLeagueSlug,
|
|
a.AvatarUrl,
|
|
a.FieldPosition,
|
|
a.Status,
|
|
a.ShirtNumber,
|
|
}
|
|
batch.Queue(createOrUpdatePlayers, vals...)
|
|
}
|
|
br := q.db.SendBatch(ctx, batch)
|
|
return &CreateOrUpdatePlayersBatchResults{br, len(arg), false}
|
|
}
|
|
|
|
func (b *CreateOrUpdatePlayersBatchResults) Exec(f func(int, error)) {
|
|
defer b.br.Close()
|
|
for t := 0; t < b.tot; t++ {
|
|
if b.closed {
|
|
if f != nil {
|
|
f(t, ErrBatchAlreadyClosed)
|
|
}
|
|
continue
|
|
}
|
|
_, err := b.br.Exec()
|
|
if f != nil {
|
|
f(t, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (b *CreateOrUpdatePlayersBatchResults) Close() error {
|
|
b.closed = true
|
|
return b.br.Close()
|
|
}
|
|
|
|
const createOrUpdateTeams = `-- name: CreateOrUpdateTeams :batchexec
|
|
INSERT INTO teams (slug, display_name, country_slug, domestic_league_slug, short_name, picture_url, team_type)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
ON CONFLICT (slug) DO UPDATE
|
|
SET display_name = $2, country_slug = $3, domestic_league_slug = $4, short_name = $5, picture_url = $6, team_type = $7
|
|
`
|
|
|
|
type CreateOrUpdateTeamsBatchResults struct {
|
|
br pgx.BatchResults
|
|
tot int
|
|
closed bool
|
|
}
|
|
|
|
type CreateOrUpdateTeamsParams struct {
|
|
Slug string
|
|
DisplayName string
|
|
CountrySlug string
|
|
DomesticLeagueSlug *string
|
|
ShortName string
|
|
PictureUrl string
|
|
TeamType string
|
|
}
|
|
|
|
func (q *Queries) CreateOrUpdateTeams(ctx context.Context, arg []CreateOrUpdateTeamsParams) *CreateOrUpdateTeamsBatchResults {
|
|
batch := &pgx.Batch{}
|
|
for _, a := range arg {
|
|
vals := []interface{}{
|
|
a.Slug,
|
|
a.DisplayName,
|
|
a.CountrySlug,
|
|
a.DomesticLeagueSlug,
|
|
a.ShortName,
|
|
a.PictureUrl,
|
|
a.TeamType,
|
|
}
|
|
batch.Queue(createOrUpdateTeams, vals...)
|
|
}
|
|
br := q.db.SendBatch(ctx, batch)
|
|
return &CreateOrUpdateTeamsBatchResults{br, len(arg), false}
|
|
}
|
|
|
|
func (b *CreateOrUpdateTeamsBatchResults) Exec(f func(int, error)) {
|
|
defer b.br.Close()
|
|
for t := 0; t < b.tot; t++ {
|
|
if b.closed {
|
|
if f != nil {
|
|
f(t, ErrBatchAlreadyClosed)
|
|
}
|
|
continue
|
|
}
|
|
_, err := b.br.Exec()
|
|
if f != nil {
|
|
f(t, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (b *CreateOrUpdateTeamsBatchResults) Close() error {
|
|
b.closed = true
|
|
return b.br.Close()
|
|
}
|