Skip to content

Commit

Permalink
fix: support scan float32 to float32
Browse files Browse the repository at this point in the history
  • Loading branch information
j2gg0s committed Dec 18, 2024
1 parent 014b142 commit 281274e
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion schema/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func init() {
reflect.Uint32: scanUint64,
reflect.Uint64: scanUint64,
reflect.Uintptr: scanUint64,
reflect.Float32: scanFloat64,
reflect.Float32: scanFloat32,
reflect.Float64: scanFloat64,
reflect.Complex64: nil,
reflect.Complex128: nil,
Expand Down Expand Up @@ -214,6 +214,36 @@ func scanUint64(dest reflect.Value, src interface{}) error {
}
}

func scanFloat32(dest reflect.Value, src interface{}) error {
switch src := src.(type) {
case nil:
dest.SetFloat(0)
return nil
case float32:
dest.SetFloat(float64(src))
return nil
case float64:
dest.SetFloat(src)
return nil
case []byte:
f, err := strconv.ParseFloat(internal.String(src), 64)
if err != nil {
return err
}
dest.SetFloat(f)
return nil
case string:
f, err := strconv.ParseFloat(src, 64)
if err != nil {
return err
}
dest.SetFloat(f)
return nil
default:
return scanError(dest.Type(), src)
}
}

func scanFloat64(dest reflect.Value, src interface{}) error {
switch src := src.(type) {
case nil:
Expand Down

0 comments on commit 281274e

Please sign in to comment.