Yimaru-BackEnd/db/query/odds.sql
OneTap Technologies aba4b89bb0 adding getby odd id
2025-04-12 09:27:41 +03:00

92 lines
1.7 KiB
SQL

-- name: InsertNonLiveOdd :exec
INSERT INTO odds (
event_id,
fi,
raw_event_id,
market_type,
market_name,
market_category,
market_id,
header,
name,
handicap,
odds_value,
section,
category,
raw_odds,
is_active,
source,
fetched_at
) VALUES (
$1, $2, $3, $4, $5, $6, $7,
$8, $9, $10, $11, $12, $13, $14,
true, 'b365api', now()
)
ON CONFLICT (event_id, market_id, header, name, handicap) DO UPDATE SET
odds_value = EXCLUDED.odds_value,
raw_odds = EXCLUDED.raw_odds,
market_type = EXCLUDED.market_type,
market_name = EXCLUDED.market_name,
market_category = EXCLUDED.market_category,
fetched_at = now(),
is_active = true,
source = 'b365api',
fi = EXCLUDED.fi,
raw_event_id = EXCLUDED.raw_event_id;
-- name: GetPrematchOdds :many
SELECT
id,
event_id,
fi,
raw_event_id,
market_type,
market_name,
market_category,
market_id,
header,
name,
handicap,
odds_value,
section,
category,
raw_odds,
fetched_at,
source,
is_active
FROM odds
WHERE event_id = $1 AND is_active = true AND source = 'b365api';
-- name: GetALLPrematchOdds :many
SELECT
id,
event_id,
fi,
market_type,
market_name,
market_category,
market_id,
name,
handicap,
odds_value,
section,
category,
raw_odds,
fetched_at,
source,
is_active
FROM odds
WHERE is_active = true AND source = 'b365api';
-- name: GetRawOddsByID :one
SELECT
id,
event_id,
raw_odds,
fetched_at
FROM odds
WHERE
raw_odds @> $1::jsonb AND
is_active = true AND
source = 'b365api'
LIMIT 1;