887 lines
25 KiB
Go
887 lines
25 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: events.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const DeleteEvent = `-- name: DeleteEvent :exec
|
|
DELETE FROM events
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteEvent(ctx context.Context, id string) error {
|
|
_, err := q.db.Exec(ctx, DeleteEvent, id)
|
|
return err
|
|
}
|
|
|
|
const GetAllUpcomingEvents = `-- name: GetAllUpcomingEvents :many
|
|
SELECT id, sport_id, match_name, home_team, away_team, home_team_id, away_team_id, home_kit_image, away_kit_image, league_id, league_name, start_time, score, match_minute, timer_status, added_time, match_period, is_live, status, fetched_at, source, default_is_active, default_is_featured, default_winning_upper_limit, is_monitored, league_cc
|
|
FROM event_with_country
|
|
WHERE start_time > now()
|
|
AND is_live = false
|
|
AND status = 'upcoming'
|
|
ORDER BY start_time ASC
|
|
`
|
|
|
|
func (q *Queries) GetAllUpcomingEvents(ctx context.Context) ([]EventWithCountry, error) {
|
|
rows, err := q.db.Query(ctx, GetAllUpcomingEvents)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []EventWithCountry
|
|
for rows.Next() {
|
|
var i EventWithCountry
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.SportID,
|
|
&i.MatchName,
|
|
&i.HomeTeam,
|
|
&i.AwayTeam,
|
|
&i.HomeTeamID,
|
|
&i.AwayTeamID,
|
|
&i.HomeKitImage,
|
|
&i.AwayKitImage,
|
|
&i.LeagueID,
|
|
&i.LeagueName,
|
|
&i.StartTime,
|
|
&i.Score,
|
|
&i.MatchMinute,
|
|
&i.TimerStatus,
|
|
&i.AddedTime,
|
|
&i.MatchPeriod,
|
|
&i.IsLive,
|
|
&i.Status,
|
|
&i.FetchedAt,
|
|
&i.Source,
|
|
&i.DefaultIsActive,
|
|
&i.DefaultIsFeatured,
|
|
&i.DefaultWinningUpperLimit,
|
|
&i.IsMonitored,
|
|
&i.LeagueCc,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetEventWithSettingByID = `-- name: GetEventWithSettingByID :one
|
|
SELECT e.id, e.sport_id, e.match_name, e.home_team, e.away_team, e.home_team_id, e.away_team_id, e.home_kit_image, e.away_kit_image, e.league_id, e.league_name, e.start_time, e.score, e.match_minute, e.timer_status, e.added_time, e.match_period, e.is_live, e.status, e.fetched_at, e.source, e.default_is_active, e.default_is_featured, e.default_winning_upper_limit, e.is_monitored,
|
|
ces.company_id,
|
|
COALESCE(ces.is_active, e.default_is_active) AS is_active,
|
|
COALESCE(ces.is_featured, e.default_is_featured) AS is_featured,
|
|
COALESCE(
|
|
ces.winning_upper_limit,
|
|
e.default_winning_upper_limit
|
|
) AS winning_upper_limit,
|
|
ces.updated_at,
|
|
l.country_code as league_cc
|
|
FROM events e
|
|
LEFT JOIN company_event_settings ces ON e.id = ces.event_id
|
|
AND ces.company_id = $2
|
|
JOIN leagues l ON l.id = e.league_id
|
|
WHERE e.id = $1
|
|
AND is_live = false
|
|
AND status = 'upcoming'
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetEventWithSettingByIDParams struct {
|
|
ID string `json:"id"`
|
|
CompanyID int64 `json:"company_id"`
|
|
}
|
|
|
|
type GetEventWithSettingByIDRow struct {
|
|
ID string `json:"id"`
|
|
SportID int32 `json:"sport_id"`
|
|
MatchName string `json:"match_name"`
|
|
HomeTeam string `json:"home_team"`
|
|
AwayTeam string `json:"away_team"`
|
|
HomeTeamID int64 `json:"home_team_id"`
|
|
AwayTeamID int64 `json:"away_team_id"`
|
|
HomeKitImage string `json:"home_kit_image"`
|
|
AwayKitImage string `json:"away_kit_image"`
|
|
LeagueID int64 `json:"league_id"`
|
|
LeagueName string `json:"league_name"`
|
|
StartTime pgtype.Timestamp `json:"start_time"`
|
|
Score pgtype.Text `json:"score"`
|
|
MatchMinute pgtype.Int4 `json:"match_minute"`
|
|
TimerStatus pgtype.Text `json:"timer_status"`
|
|
AddedTime pgtype.Int4 `json:"added_time"`
|
|
MatchPeriod pgtype.Int4 `json:"match_period"`
|
|
IsLive bool `json:"is_live"`
|
|
Status string `json:"status"`
|
|
FetchedAt pgtype.Timestamp `json:"fetched_at"`
|
|
Source string `json:"source"`
|
|
DefaultIsActive bool `json:"default_is_active"`
|
|
DefaultIsFeatured bool `json:"default_is_featured"`
|
|
DefaultWinningUpperLimit int64 `json:"default_winning_upper_limit"`
|
|
IsMonitored bool `json:"is_monitored"`
|
|
CompanyID pgtype.Int8 `json:"company_id"`
|
|
IsActive bool `json:"is_active"`
|
|
IsFeatured bool `json:"is_featured"`
|
|
WinningUpperLimit int32 `json:"winning_upper_limit"`
|
|
UpdatedAt pgtype.Timestamp `json:"updated_at"`
|
|
LeagueCc pgtype.Text `json:"league_cc"`
|
|
}
|
|
|
|
func (q *Queries) GetEventWithSettingByID(ctx context.Context, arg GetEventWithSettingByIDParams) (GetEventWithSettingByIDRow, error) {
|
|
row := q.db.QueryRow(ctx, GetEventWithSettingByID, arg.ID, arg.CompanyID)
|
|
var i GetEventWithSettingByIDRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.SportID,
|
|
&i.MatchName,
|
|
&i.HomeTeam,
|
|
&i.AwayTeam,
|
|
&i.HomeTeamID,
|
|
&i.AwayTeamID,
|
|
&i.HomeKitImage,
|
|
&i.AwayKitImage,
|
|
&i.LeagueID,
|
|
&i.LeagueName,
|
|
&i.StartTime,
|
|
&i.Score,
|
|
&i.MatchMinute,
|
|
&i.TimerStatus,
|
|
&i.AddedTime,
|
|
&i.MatchPeriod,
|
|
&i.IsLive,
|
|
&i.Status,
|
|
&i.FetchedAt,
|
|
&i.Source,
|
|
&i.DefaultIsActive,
|
|
&i.DefaultIsFeatured,
|
|
&i.DefaultWinningUpperLimit,
|
|
&i.IsMonitored,
|
|
&i.CompanyID,
|
|
&i.IsActive,
|
|
&i.IsFeatured,
|
|
&i.WinningUpperLimit,
|
|
&i.UpdatedAt,
|
|
&i.LeagueCc,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetEventsWithSettings = `-- name: GetEventsWithSettings :many
|
|
SELECT e.id, e.sport_id, e.match_name, e.home_team, e.away_team, e.home_team_id, e.away_team_id, e.home_kit_image, e.away_kit_image, e.league_id, e.league_name, e.start_time, e.score, e.match_minute, e.timer_status, e.added_time, e.match_period, e.is_live, e.status, e.fetched_at, e.source, e.default_is_active, e.default_is_featured, e.default_winning_upper_limit, e.is_monitored,
|
|
ces.company_id,
|
|
COALESCE(ces.is_active, e.default_is_active) AS is_active,
|
|
COALESCE(ces.is_featured, e.default_is_featured) AS is_featured,
|
|
COALESCE(
|
|
ces.winning_upper_limit,
|
|
e.default_winning_upper_limit
|
|
) AS winning_upper_limit,
|
|
ces.updated_at,
|
|
l.country_code as league_cc
|
|
FROM events e
|
|
LEFT JOIN company_event_settings ces ON e.id = ces.event_id
|
|
AND ces.company_id = $1
|
|
JOIN leagues l ON l.id = e.league_id
|
|
WHERE start_time > now()
|
|
AND is_live = false
|
|
AND status = 'upcoming'
|
|
AND (
|
|
league_id = $2
|
|
OR $2 IS NULL
|
|
)
|
|
AND (
|
|
e.sport_id = $3
|
|
OR $3 IS NULL
|
|
)
|
|
AND (
|
|
match_name ILIKE '%' || $4 || '%'
|
|
OR league_name ILIKE '%' || $4 || '%'
|
|
OR $4 IS NULL
|
|
)
|
|
AND (
|
|
start_time < $5
|
|
OR $5 IS NULL
|
|
)
|
|
AND (
|
|
start_time > $6
|
|
OR $6 IS NULL
|
|
)
|
|
AND (
|
|
l.country_code = $7
|
|
OR $7 IS NULL
|
|
)
|
|
AND (
|
|
ces.is_featured = $8
|
|
OR e.default_is_featured = $8
|
|
OR $8 IS NULL
|
|
)
|
|
AND (
|
|
ces.is_active = $9
|
|
OR e.default_is_active = $9
|
|
OR $9 IS NULL
|
|
)
|
|
ORDER BY start_time ASC
|
|
LIMIT $11 OFFSET $10
|
|
`
|
|
|
|
type GetEventsWithSettingsParams struct {
|
|
CompanyID int64 `json:"company_id"`
|
|
LeagueID pgtype.Int8 `json:"league_id"`
|
|
SportID pgtype.Int4 `json:"sport_id"`
|
|
Query pgtype.Text `json:"query"`
|
|
LastStartTime pgtype.Timestamp `json:"last_start_time"`
|
|
FirstStartTime pgtype.Timestamp `json:"first_start_time"`
|
|
CountryCode pgtype.Text `json:"country_code"`
|
|
IsFeatured pgtype.Bool `json:"is_featured"`
|
|
IsActive pgtype.Bool `json:"is_active"`
|
|
Offset pgtype.Int4 `json:"offset"`
|
|
Limit pgtype.Int4 `json:"limit"`
|
|
}
|
|
|
|
type GetEventsWithSettingsRow struct {
|
|
ID string `json:"id"`
|
|
SportID int32 `json:"sport_id"`
|
|
MatchName string `json:"match_name"`
|
|
HomeTeam string `json:"home_team"`
|
|
AwayTeam string `json:"away_team"`
|
|
HomeTeamID int64 `json:"home_team_id"`
|
|
AwayTeamID int64 `json:"away_team_id"`
|
|
HomeKitImage string `json:"home_kit_image"`
|
|
AwayKitImage string `json:"away_kit_image"`
|
|
LeagueID int64 `json:"league_id"`
|
|
LeagueName string `json:"league_name"`
|
|
StartTime pgtype.Timestamp `json:"start_time"`
|
|
Score pgtype.Text `json:"score"`
|
|
MatchMinute pgtype.Int4 `json:"match_minute"`
|
|
TimerStatus pgtype.Text `json:"timer_status"`
|
|
AddedTime pgtype.Int4 `json:"added_time"`
|
|
MatchPeriod pgtype.Int4 `json:"match_period"`
|
|
IsLive bool `json:"is_live"`
|
|
Status string `json:"status"`
|
|
FetchedAt pgtype.Timestamp `json:"fetched_at"`
|
|
Source string `json:"source"`
|
|
DefaultIsActive bool `json:"default_is_active"`
|
|
DefaultIsFeatured bool `json:"default_is_featured"`
|
|
DefaultWinningUpperLimit int64 `json:"default_winning_upper_limit"`
|
|
IsMonitored bool `json:"is_monitored"`
|
|
CompanyID pgtype.Int8 `json:"company_id"`
|
|
IsActive bool `json:"is_active"`
|
|
IsFeatured bool `json:"is_featured"`
|
|
WinningUpperLimit int32 `json:"winning_upper_limit"`
|
|
UpdatedAt pgtype.Timestamp `json:"updated_at"`
|
|
LeagueCc pgtype.Text `json:"league_cc"`
|
|
}
|
|
|
|
func (q *Queries) GetEventsWithSettings(ctx context.Context, arg GetEventsWithSettingsParams) ([]GetEventsWithSettingsRow, error) {
|
|
rows, err := q.db.Query(ctx, GetEventsWithSettings,
|
|
arg.CompanyID,
|
|
arg.LeagueID,
|
|
arg.SportID,
|
|
arg.Query,
|
|
arg.LastStartTime,
|
|
arg.FirstStartTime,
|
|
arg.CountryCode,
|
|
arg.IsFeatured,
|
|
arg.IsActive,
|
|
arg.Offset,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetEventsWithSettingsRow
|
|
for rows.Next() {
|
|
var i GetEventsWithSettingsRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.SportID,
|
|
&i.MatchName,
|
|
&i.HomeTeam,
|
|
&i.AwayTeam,
|
|
&i.HomeTeamID,
|
|
&i.AwayTeamID,
|
|
&i.HomeKitImage,
|
|
&i.AwayKitImage,
|
|
&i.LeagueID,
|
|
&i.LeagueName,
|
|
&i.StartTime,
|
|
&i.Score,
|
|
&i.MatchMinute,
|
|
&i.TimerStatus,
|
|
&i.AddedTime,
|
|
&i.MatchPeriod,
|
|
&i.IsLive,
|
|
&i.Status,
|
|
&i.FetchedAt,
|
|
&i.Source,
|
|
&i.DefaultIsActive,
|
|
&i.DefaultIsFeatured,
|
|
&i.DefaultWinningUpperLimit,
|
|
&i.IsMonitored,
|
|
&i.CompanyID,
|
|
&i.IsActive,
|
|
&i.IsFeatured,
|
|
&i.WinningUpperLimit,
|
|
&i.UpdatedAt,
|
|
&i.LeagueCc,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetExpiredEvents = `-- name: GetExpiredEvents :many
|
|
SELECT id, sport_id, match_name, home_team, away_team, home_team_id, away_team_id, home_kit_image, away_kit_image, league_id, league_name, start_time, score, match_minute, timer_status, added_time, match_period, is_live, status, fetched_at, source, default_is_active, default_is_featured, default_winning_upper_limit, is_monitored, league_cc
|
|
FROM event_with_country
|
|
WHERE start_time < now()
|
|
and (
|
|
status = $1
|
|
OR $1 IS NULL
|
|
)
|
|
ORDER BY start_time ASC
|
|
`
|
|
|
|
func (q *Queries) GetExpiredEvents(ctx context.Context, status pgtype.Text) ([]EventWithCountry, error) {
|
|
rows, err := q.db.Query(ctx, GetExpiredEvents, status)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []EventWithCountry
|
|
for rows.Next() {
|
|
var i EventWithCountry
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.SportID,
|
|
&i.MatchName,
|
|
&i.HomeTeam,
|
|
&i.AwayTeam,
|
|
&i.HomeTeamID,
|
|
&i.AwayTeamID,
|
|
&i.HomeKitImage,
|
|
&i.AwayKitImage,
|
|
&i.LeagueID,
|
|
&i.LeagueName,
|
|
&i.StartTime,
|
|
&i.Score,
|
|
&i.MatchMinute,
|
|
&i.TimerStatus,
|
|
&i.AddedTime,
|
|
&i.MatchPeriod,
|
|
&i.IsLive,
|
|
&i.Status,
|
|
&i.FetchedAt,
|
|
&i.Source,
|
|
&i.DefaultIsActive,
|
|
&i.DefaultIsFeatured,
|
|
&i.DefaultWinningUpperLimit,
|
|
&i.IsMonitored,
|
|
&i.LeagueCc,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetPaginatedUpcomingEvents = `-- name: GetPaginatedUpcomingEvents :many
|
|
SELECT id, sport_id, match_name, home_team, away_team, home_team_id, away_team_id, home_kit_image, away_kit_image, league_id, league_name, start_time, score, match_minute, timer_status, added_time, match_period, is_live, status, fetched_at, source, default_is_active, default_is_featured, default_winning_upper_limit, is_monitored, league_cc
|
|
FROM event_with_country
|
|
WHERE start_time > now()
|
|
AND is_live = false
|
|
AND status = 'upcoming'
|
|
AND (
|
|
league_id = $1
|
|
OR $1 IS NULL
|
|
)
|
|
AND (
|
|
sport_id = $2
|
|
OR $2 IS NULL
|
|
)
|
|
AND (
|
|
match_name ILIKE '%' || $3 || '%'
|
|
OR league_name ILIKE '%' || $3 || '%'
|
|
OR $3 IS NULL
|
|
)
|
|
AND (
|
|
start_time < $4
|
|
OR $4 IS NULL
|
|
)
|
|
AND (
|
|
start_time > $5
|
|
OR $5 IS NULL
|
|
)
|
|
AND (
|
|
league_cc = $6
|
|
OR $6 IS NULL
|
|
)
|
|
ORDER BY start_time ASC
|
|
LIMIT $8 OFFSET $7
|
|
`
|
|
|
|
type GetPaginatedUpcomingEventsParams struct {
|
|
LeagueID pgtype.Int8 `json:"league_id"`
|
|
SportID pgtype.Int4 `json:"sport_id"`
|
|
Query pgtype.Text `json:"query"`
|
|
LastStartTime pgtype.Timestamp `json:"last_start_time"`
|
|
FirstStartTime pgtype.Timestamp `json:"first_start_time"`
|
|
CountryCode pgtype.Text `json:"country_code"`
|
|
Offset pgtype.Int4 `json:"offset"`
|
|
Limit pgtype.Int4 `json:"limit"`
|
|
}
|
|
|
|
func (q *Queries) GetPaginatedUpcomingEvents(ctx context.Context, arg GetPaginatedUpcomingEventsParams) ([]EventWithCountry, error) {
|
|
rows, err := q.db.Query(ctx, GetPaginatedUpcomingEvents,
|
|
arg.LeagueID,
|
|
arg.SportID,
|
|
arg.Query,
|
|
arg.LastStartTime,
|
|
arg.FirstStartTime,
|
|
arg.CountryCode,
|
|
arg.Offset,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []EventWithCountry
|
|
for rows.Next() {
|
|
var i EventWithCountry
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.SportID,
|
|
&i.MatchName,
|
|
&i.HomeTeam,
|
|
&i.AwayTeam,
|
|
&i.HomeTeamID,
|
|
&i.AwayTeamID,
|
|
&i.HomeKitImage,
|
|
&i.AwayKitImage,
|
|
&i.LeagueID,
|
|
&i.LeagueName,
|
|
&i.StartTime,
|
|
&i.Score,
|
|
&i.MatchMinute,
|
|
&i.TimerStatus,
|
|
&i.AddedTime,
|
|
&i.MatchPeriod,
|
|
&i.IsLive,
|
|
&i.Status,
|
|
&i.FetchedAt,
|
|
&i.Source,
|
|
&i.DefaultIsActive,
|
|
&i.DefaultIsFeatured,
|
|
&i.DefaultWinningUpperLimit,
|
|
&i.IsMonitored,
|
|
&i.LeagueCc,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetTotalCompanyEvents = `-- name: GetTotalCompanyEvents :one
|
|
SELECT COUNT(*)
|
|
FROM events e
|
|
LEFT JOIN company_event_settings ces ON e.id = ces.event_id
|
|
AND ces.company_id = $1
|
|
JOIN leagues l ON l.id = e.league_id
|
|
WHERE is_live = false
|
|
AND status = 'upcoming'
|
|
AND (
|
|
league_id = $2
|
|
OR $2 IS NULL
|
|
)
|
|
AND (
|
|
e.sport_id = $3
|
|
OR $3 IS NULL
|
|
)
|
|
AND (
|
|
match_name ILIKE '%' || $4 || '%'
|
|
OR league_name ILIKE '%' || $4 || '%'
|
|
OR $4 IS NULL
|
|
)
|
|
AND (
|
|
start_time < $5
|
|
OR $5 IS NULL
|
|
)
|
|
AND (
|
|
start_time > $6
|
|
OR $6 IS NULL
|
|
)
|
|
AND (
|
|
l.country_code = $7
|
|
OR $7 IS NULL
|
|
)
|
|
AND (
|
|
ces.is_featured = $8
|
|
OR e.default_is_featured = $8
|
|
OR $8 IS NULL
|
|
)
|
|
AND (
|
|
ces.is_active = $9
|
|
OR e.default_is_active = $9
|
|
OR $9 IS NULL
|
|
)
|
|
`
|
|
|
|
type GetTotalCompanyEventsParams struct {
|
|
CompanyID int64 `json:"company_id"`
|
|
LeagueID pgtype.Int8 `json:"league_id"`
|
|
SportID pgtype.Int4 `json:"sport_id"`
|
|
Query pgtype.Text `json:"query"`
|
|
LastStartTime pgtype.Timestamp `json:"last_start_time"`
|
|
FirstStartTime pgtype.Timestamp `json:"first_start_time"`
|
|
CountryCode pgtype.Text `json:"country_code"`
|
|
IsFeatured pgtype.Bool `json:"is_featured"`
|
|
IsActive pgtype.Bool `json:"is_active"`
|
|
}
|
|
|
|
func (q *Queries) GetTotalCompanyEvents(ctx context.Context, arg GetTotalCompanyEventsParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, GetTotalCompanyEvents,
|
|
arg.CompanyID,
|
|
arg.LeagueID,
|
|
arg.SportID,
|
|
arg.Query,
|
|
arg.LastStartTime,
|
|
arg.FirstStartTime,
|
|
arg.CountryCode,
|
|
arg.IsFeatured,
|
|
arg.IsActive,
|
|
)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const GetTotalEvents = `-- name: GetTotalEvents :one
|
|
SELECT COUNT(*)
|
|
FROM event_with_country
|
|
WHERE is_live = false
|
|
AND status = 'upcoming'
|
|
AND (
|
|
league_id = $1
|
|
OR $1 IS NULL
|
|
)
|
|
AND (
|
|
sport_id = $2
|
|
OR $2 IS NULL
|
|
)
|
|
AND (
|
|
match_name ILIKE '%' || $3 || '%'
|
|
OR league_name ILIKE '%' || $3 || '%'
|
|
OR $3 IS NULL
|
|
)
|
|
AND (
|
|
start_time < $4
|
|
OR $4 IS NULL
|
|
)
|
|
AND (
|
|
start_time > $5
|
|
OR $5 IS NULL
|
|
)
|
|
AND (
|
|
league_cc = $6
|
|
OR $6 IS NULL
|
|
)
|
|
`
|
|
|
|
type GetTotalEventsParams struct {
|
|
LeagueID pgtype.Int8 `json:"league_id"`
|
|
SportID pgtype.Int4 `json:"sport_id"`
|
|
Query pgtype.Text `json:"query"`
|
|
LastStartTime pgtype.Timestamp `json:"last_start_time"`
|
|
FirstStartTime pgtype.Timestamp `json:"first_start_time"`
|
|
CountryCode pgtype.Text `json:"country_code"`
|
|
}
|
|
|
|
func (q *Queries) GetTotalEvents(ctx context.Context, arg GetTotalEventsParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, GetTotalEvents,
|
|
arg.LeagueID,
|
|
arg.SportID,
|
|
arg.Query,
|
|
arg.LastStartTime,
|
|
arg.FirstStartTime,
|
|
arg.CountryCode,
|
|
)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const GetUpcomingByID = `-- name: GetUpcomingByID :one
|
|
SELECT id, sport_id, match_name, home_team, away_team, home_team_id, away_team_id, home_kit_image, away_kit_image, league_id, league_name, start_time, score, match_minute, timer_status, added_time, match_period, is_live, status, fetched_at, source, default_is_active, default_is_featured, default_winning_upper_limit, is_monitored, league_cc
|
|
FROM event_with_country
|
|
WHERE id = $1
|
|
AND is_live = false
|
|
AND status = 'upcoming'
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetUpcomingByID(ctx context.Context, id string) (EventWithCountry, error) {
|
|
row := q.db.QueryRow(ctx, GetUpcomingByID, id)
|
|
var i EventWithCountry
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.SportID,
|
|
&i.MatchName,
|
|
&i.HomeTeam,
|
|
&i.AwayTeam,
|
|
&i.HomeTeamID,
|
|
&i.AwayTeamID,
|
|
&i.HomeKitImage,
|
|
&i.AwayKitImage,
|
|
&i.LeagueID,
|
|
&i.LeagueName,
|
|
&i.StartTime,
|
|
&i.Score,
|
|
&i.MatchMinute,
|
|
&i.TimerStatus,
|
|
&i.AddedTime,
|
|
&i.MatchPeriod,
|
|
&i.IsLive,
|
|
&i.Status,
|
|
&i.FetchedAt,
|
|
&i.Source,
|
|
&i.DefaultIsActive,
|
|
&i.DefaultIsFeatured,
|
|
&i.DefaultWinningUpperLimit,
|
|
&i.IsMonitored,
|
|
&i.LeagueCc,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const InsertEvent = `-- name: InsertEvent :exec
|
|
INSERT INTO events (
|
|
id,
|
|
sport_id,
|
|
match_name,
|
|
home_team,
|
|
away_team,
|
|
home_team_id,
|
|
away_team_id,
|
|
home_kit_image,
|
|
away_kit_image,
|
|
league_id,
|
|
league_name,
|
|
start_time,
|
|
is_live,
|
|
status,
|
|
source,
|
|
default_winning_upper_limit
|
|
)
|
|
VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8,
|
|
$9,
|
|
$10,
|
|
$11,
|
|
$12,
|
|
$13,
|
|
$14,
|
|
$15,
|
|
$16
|
|
) ON CONFLICT (id) DO
|
|
UPDATE
|
|
SET sport_id = EXCLUDED.sport_id,
|
|
match_name = EXCLUDED.match_name,
|
|
home_team = EXCLUDED.home_team,
|
|
away_team = EXCLUDED.away_team,
|
|
home_team_id = EXCLUDED.home_team_id,
|
|
away_team_id = EXCLUDED.away_team_id,
|
|
home_kit_image = EXCLUDED.home_kit_image,
|
|
away_kit_image = EXCLUDED.away_kit_image,
|
|
league_id = EXCLUDED.league_id,
|
|
league_name = EXCLUDED.league_name,
|
|
start_time = EXCLUDED.start_time,
|
|
score = EXCLUDED.score,
|
|
match_minute = EXCLUDED.match_minute,
|
|
timer_status = EXCLUDED.timer_status,
|
|
added_time = EXCLUDED.added_time,
|
|
match_period = EXCLUDED.match_period,
|
|
is_live = EXCLUDED.is_live,
|
|
source = EXCLUDED.source,
|
|
default_winning_upper_limit = EXCLUDED.default_winning_upper_limit,
|
|
fetched_at = now()
|
|
`
|
|
|
|
type InsertEventParams struct {
|
|
ID string `json:"id"`
|
|
SportID int32 `json:"sport_id"`
|
|
MatchName string `json:"match_name"`
|
|
HomeTeam string `json:"home_team"`
|
|
AwayTeam string `json:"away_team"`
|
|
HomeTeamID int64 `json:"home_team_id"`
|
|
AwayTeamID int64 `json:"away_team_id"`
|
|
HomeKitImage string `json:"home_kit_image"`
|
|
AwayKitImage string `json:"away_kit_image"`
|
|
LeagueID int64 `json:"league_id"`
|
|
LeagueName string `json:"league_name"`
|
|
StartTime pgtype.Timestamp `json:"start_time"`
|
|
IsLive bool `json:"is_live"`
|
|
Status string `json:"status"`
|
|
Source string `json:"source"`
|
|
DefaultWinningUpperLimit int64 `json:"default_winning_upper_limit"`
|
|
}
|
|
|
|
func (q *Queries) InsertEvent(ctx context.Context, arg InsertEventParams) error {
|
|
_, err := q.db.Exec(ctx, InsertEvent,
|
|
arg.ID,
|
|
arg.SportID,
|
|
arg.MatchName,
|
|
arg.HomeTeam,
|
|
arg.AwayTeam,
|
|
arg.HomeTeamID,
|
|
arg.AwayTeamID,
|
|
arg.HomeKitImage,
|
|
arg.AwayKitImage,
|
|
arg.LeagueID,
|
|
arg.LeagueName,
|
|
arg.StartTime,
|
|
arg.IsLive,
|
|
arg.Status,
|
|
arg.Source,
|
|
arg.DefaultWinningUpperLimit,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const IsEventMonitored = `-- name: IsEventMonitored :one
|
|
SELECT is_monitored
|
|
FROM events
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) IsEventMonitored(ctx context.Context, id string) (bool, error) {
|
|
row := q.db.QueryRow(ctx, IsEventMonitored, id)
|
|
var is_monitored bool
|
|
err := row.Scan(&is_monitored)
|
|
return is_monitored, err
|
|
}
|
|
|
|
const ListLiveEvents = `-- name: ListLiveEvents :many
|
|
SELECT id
|
|
FROM event_with_country
|
|
WHERE is_live = true
|
|
`
|
|
|
|
func (q *Queries) ListLiveEvents(ctx context.Context) ([]string, error) {
|
|
rows, err := q.db.Query(ctx, ListLiveEvents)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []string
|
|
for rows.Next() {
|
|
var id string
|
|
if err := rows.Scan(&id); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, id)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const SaveEventSettings = `-- name: SaveEventSettings :exec
|
|
INSERT INTO company_event_settings (
|
|
company_id,
|
|
event_id,
|
|
is_active,
|
|
is_featured,
|
|
winning_upper_limit
|
|
)
|
|
VALUES ($1, $2, $3, $4, $5) ON CONFLICT(company_id, event_id) DO
|
|
UPDATE
|
|
SET is_active = EXCLUDED.is_active,
|
|
is_featured = EXCLUDED.is_featured,
|
|
winning_upper_limit = EXCLUDED.winning_upper_limit
|
|
`
|
|
|
|
type SaveEventSettingsParams struct {
|
|
CompanyID int64 `json:"company_id"`
|
|
EventID string `json:"event_id"`
|
|
IsActive pgtype.Bool `json:"is_active"`
|
|
IsFeatured pgtype.Bool `json:"is_featured"`
|
|
WinningUpperLimit pgtype.Int4 `json:"winning_upper_limit"`
|
|
}
|
|
|
|
func (q *Queries) SaveEventSettings(ctx context.Context, arg SaveEventSettingsParams) error {
|
|
_, err := q.db.Exec(ctx, SaveEventSettings,
|
|
arg.CompanyID,
|
|
arg.EventID,
|
|
arg.IsActive,
|
|
arg.IsFeatured,
|
|
arg.WinningUpperLimit,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const UpdateEventMonitored = `-- name: UpdateEventMonitored :exec
|
|
UPDATE events
|
|
SET is_monitored = $1
|
|
WHERE id = $2
|
|
`
|
|
|
|
type UpdateEventMonitoredParams struct {
|
|
IsMonitored bool `json:"is_monitored"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateEventMonitored(ctx context.Context, arg UpdateEventMonitoredParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateEventMonitored, arg.IsMonitored, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const UpdateMatchResult = `-- name: UpdateMatchResult :exec
|
|
UPDATE events
|
|
SET score = $1,
|
|
status = $2
|
|
WHERE id = $3
|
|
`
|
|
|
|
type UpdateMatchResultParams struct {
|
|
Score pgtype.Text `json:"score"`
|
|
Status string `json:"status"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateMatchResult(ctx context.Context, arg UpdateMatchResultParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateMatchResult, arg.Score, arg.Status, arg.ID)
|
|
return err
|
|
}
|