Yimaru-BackEnd/gen/db/events_bet_stats.sql.go
Samuel Tariku 18689ea124 feat: Add EventWithSettings domain model and related conversion functions
- Introduced EventWithSettings and EventWithSettingsRes structs for enhanced event data handling.
- Implemented conversion functions for creating and updating event settings.
- Added support for fetching events with settings from the database.
- Created new report data structures for comprehensive reporting capabilities.
- Implemented event statistics retrieval and filtering by league and sport.
- Added handlers for event statistics endpoints in the web server.
- Introduced DateInterval type for managing time intervals in reports.
2025-10-18 11:50:17 +03:00

52 lines
1.4 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: events_bet_stats.sql
package dbgen
import (
"context"
)
const UpdateEventBetStats = `-- name: UpdateEventBetStats :exec
INSERT INTO event_bet_stats (
event_id,
number_of_bets,
total_amount,
avg_bet_amount,
total_potential_winnings,
updated_at
)
SELECT bo.event_id,
COUNT(DISTINCT b.id) AS number_of_bets,
COALESCE(SUM(b.amount), 0) AS total_amount,
COALESCE(AVG(b.amount), 0) AS avg_bet_amount,
COALESCE(SUM(b.potential_win), 0) AS total_potential_winnings,
NOW() AS updated_at
FROM bet_outcomes bo
JOIN bets b ON bo.bet_id = b.id
GROUP BY bo.event_id ON CONFLICT (event_id) DO
UPDATE
SET number_of_bets = EXCLUDED.number_of_bets,
total_amount = EXCLUDED.total_amount,
avg_bet_amount = EXCLUDED.avg_bet_amount,
total_potential_winnings = EXCLUDED.total_potential_winnings,
updated_at = EXCLUDED.updated_at
`
// Aggregate bet stats per event
func (q *Queries) UpdateEventBetStats(ctx context.Context) error {
_, err := q.db.Exec(ctx, UpdateEventBetStats)
return err
}
const UpdateEventDetailedViewMat = `-- name: UpdateEventDetailedViewMat :exec
REFRESH MATERIALIZED VIEW event_detailed_mat
`
func (q *Queries) UpdateEventDetailedViewMat(ctx context.Context) error {
_, err := q.db.Exec(ctx, UpdateEventDetailedViewMat)
return err
}