31 lines
749 B
Go
31 lines
749 B
Go
package storage
|
|
|
|
import (
|
|
"database/sql"
|
|
"log"
|
|
"strings"
|
|
|
|
"synlotto-website/internal/models"
|
|
)
|
|
|
|
func InsertThunderballResult(db *sql.DB, res models.ThunderballResult) error {
|
|
stmt := `
|
|
INSERT INTO results_thunderball (
|
|
draw_date, machine, ballset,
|
|
ball1, ball2, ball3, ball4, ball5, thunderball
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);`
|
|
|
|
_, err := db.Exec(stmt,
|
|
res.DrawDate, res.Machine, res.BallSet,
|
|
res.Ball1, res.Ball2, res.Ball3, res.Ball4, res.Ball5, res.Thunderball,
|
|
)
|
|
if err != nil {
|
|
if strings.Contains(err.Error(), "UNIQUE constraint failed") {
|
|
log.Printf("⚠️ Draw for %s already exists. Skipping insert.\n", res.DrawDate)
|
|
return nil
|
|
}
|
|
log.Println("❌ InsertThunderballResult error:", err)
|
|
}
|
|
return err
|
|
}
|