diff --git a/pkg/spectypes/sql_types.go b/pkg/spectypes/sql_types.go index 2d72ce0..43afc93 100644 --- a/pkg/spectypes/sql_types.go +++ b/pkg/spectypes/sql_types.go @@ -74,6 +74,10 @@ func (n *SqlNull[T]) Scan(value any) error { return n.FromString(v) case []byte: return n.FromString(string(v)) + case float32, float64: + return n.FromString(fmt.Sprintf("%f", value)) + case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64: + return n.FromString(fmt.Sprintf("%d", value)) default: return n.FromString(fmt.Sprintf("%v", value)) } @@ -94,6 +98,10 @@ func (n *SqlNull[T]) FromString(s string) error { reflect.ValueOf(&n.Val).Elem().SetInt(i) n.Valid = true } + if f, err := strconv.ParseFloat(s, 64); err == nil { + reflect.ValueOf(&n.Val).Elem().SetInt(int64(f)) + n.Valid = true + } case float32, float64: if f, err := strconv.ParseFloat(s, 64); err == nil { reflect.ValueOf(&n.Val).Elem().SetFloat(f)