mirror of
https://github.com/nprasad2077/NBA_Go.git
synced 2026-09-22 14:05:13 +00:00
boxscore batch import
This commit is contained in:
+32
-10
@@ -1,27 +1,49 @@
|
||||
package services
|
||||
|
||||
import "strconv"
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"gorm.io/gorm/schema"
|
||||
)
|
||||
|
||||
// mustAtoi parses s into an int, or returns 0 on error.
|
||||
// This function remains unchanged for general use.
|
||||
func mustAtoi(s string) int {
|
||||
i, _ := strconv.Atoi(s)
|
||||
return i
|
||||
i, _ := strconv.Atoi(s)
|
||||
return i
|
||||
}
|
||||
|
||||
// mustAtoiWithSign handles strings that might have a "+" or "-" sign.
|
||||
// mustAtoiWithSign is the new function to handle strings that might
|
||||
// have a "+" or "-" sign, like the 'plus_minus' stat.
|
||||
func mustAtoiWithSign(s string) int {
|
||||
if s == "" {
|
||||
return 0
|
||||
}
|
||||
// The strconv.Atoi function handles the sign automatically.
|
||||
// strconv.Atoi already handles signs correctly. This function
|
||||
// provides a clear, semantic name for its specific purpose.
|
||||
i, _ := strconv.Atoi(s)
|
||||
return i
|
||||
}
|
||||
|
||||
// mustParseFloat parses s into a float64, or returns 0.0 on error.
|
||||
func mustParseFloat(s string) float64 {
|
||||
f, _ := strconv.ParseFloat(s, 64)
|
||||
return f
|
||||
f, _ := strconv.ParseFloat(s, 64)
|
||||
return f
|
||||
}
|
||||
|
||||
// getModelColumns uses reflection to discover model columns for dynamic upserts.
|
||||
func getModelColumns(instance interface{}) []string {
|
||||
s, err := schema.Parse(instance, &sync.Map{}, schema.NamingStrategy{})
|
||||
if err != nil {
|
||||
log.Printf("Failed to parse GORM schema: %v", err)
|
||||
return []string{}
|
||||
}
|
||||
|
||||
columns := make([]string, 0, len(s.Fields))
|
||||
for _, field := range s.Fields {
|
||||
if field.PrimaryKey {
|
||||
continue // Skip primary key columns
|
||||
}
|
||||
columns = append(columns, field.DBName)
|
||||
}
|
||||
return columns
|
||||
}
|
||||
Reference in New Issue
Block a user