sorarebuddy/model/sql/competition.sql

40 lines
1.2 KiB
SQL

-- 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;
-- name: GetCompetitionBySlug :one
SELECT sqlc.embed(competitions),
sqlc.embed(zones),
sqlc.embed(countries)
FROM competitions
LEFT JOIN zones ON competitions.zone_id = zones.id
LEFT JOIN countries ON competitions.country_slug = countries.slug
WHERE competitions.slug = $1;
-- name: GetAllCompetitions :many
SELECT sqlc.embed(competitions),
sqlc.embed(zones),
sqlc.embed(countries)
FROM competitions
LEFT JOIN zones ON competitions.zone_id = zones.id
LEFT JOIN countries ON competitions.country_slug = countries.slug;