235 lines
5.5 KiB
Go
235 lines
5.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.25.0
|
|
// source: batch.go
|
|
|
|
package model
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"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()
|
|
}
|