From 13cd287a6f2ce6d5215ae4361789596e5f1eefe9 Mon Sep 17 00:00:00 2001 From: Steve Fan <29133953+stevefan1999-personal@users.noreply.github.com> Date: Mon, 20 Jul 2020 21:09:46 +0800 Subject: [PATCH] workaround some shitty db that returns capitalized letter for column name --- go.mod | 1 + scan.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/go.mod b/go.mod index faf63a46..5f1a5fcc 100644 --- a/go.mod +++ b/go.mod @@ -5,4 +5,5 @@ go 1.14 require ( github.com/jinzhu/inflection v1.0.0 github.com/jinzhu/now v1.1.1 + github.com/thoas/go-funk v0.7.0 ) diff --git a/scan.go b/scan.go index 0b199029..2e5e770e 100644 --- a/scan.go +++ b/scan.go @@ -5,6 +5,8 @@ import ( "reflect" "strings" + "github.com/thoas/go-funk" + "gorm.io/gorm/schema" ) @@ -12,6 +14,10 @@ func Scan(rows *sql.Rows, db *DB, initialized bool) { columns, _ := rows.Columns() values := make([]interface{}, len(columns)) + columns = funk.Map(columns, func(s string) string { + return strings.ToLower(s) + }).([]string) + switch dest := db.Statement.Dest.(type) { case map[string]interface{}, *map[string]interface{}: if initialized || rows.Next() {