update
This commit is contained in:
17
db/db.go
17
db/db.go
@@ -82,19 +82,36 @@ func ConvertToSQLParams(input interface{}, output interface{}) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle fields of type sql.NullString, sql.NullInt64, and normal string/int64 fields
|
||||||
switch outputField.Type() {
|
switch outputField.Type() {
|
||||||
case reflect.TypeOf(sql.NullString{}):
|
case reflect.TypeOf(sql.NullString{}):
|
||||||
|
// Handle sql.NullString
|
||||||
if inputField.Kind() == reflect.Ptr && inputField.IsNil() {
|
if inputField.Kind() == reflect.Ptr && inputField.IsNil() {
|
||||||
outputField.Set(reflect.ValueOf(sql.NullString{Valid: false}))
|
outputField.Set(reflect.ValueOf(sql.NullString{Valid: false}))
|
||||||
} else {
|
} else {
|
||||||
outputField.Set(reflect.ValueOf(sql.NullString{String: inputField.String(), Valid: true}))
|
outputField.Set(reflect.ValueOf(sql.NullString{String: inputField.String(), Valid: true}))
|
||||||
}
|
}
|
||||||
|
|
||||||
case reflect.TypeOf(sql.NullInt64{}):
|
case reflect.TypeOf(sql.NullInt64{}):
|
||||||
|
// Handle sql.NullInt64
|
||||||
if inputField.Int() == 0 {
|
if inputField.Int() == 0 {
|
||||||
outputField.Set(reflect.ValueOf(sql.NullInt64{Valid: false}))
|
outputField.Set(reflect.ValueOf(sql.NullInt64{Valid: false}))
|
||||||
} else {
|
} else {
|
||||||
outputField.Set(reflect.ValueOf(sql.NullInt64{Int64: inputField.Int(), Valid: true}))
|
outputField.Set(reflect.ValueOf(sql.NullInt64{Int64: inputField.Int(), Valid: true}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case reflect.TypeOf(""):
|
||||||
|
// Handle normal string fields
|
||||||
|
if inputField.Kind() == reflect.Ptr && inputField.IsNil() {
|
||||||
|
outputField.SetString("") // Set to empty string if input is nil
|
||||||
|
} else {
|
||||||
|
outputField.SetString(inputField.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
case reflect.TypeOf(int64(0)):
|
||||||
|
// Handle normal int64 fields
|
||||||
|
outputField.SetInt(inputField.Int())
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user