From a980201d215702c3e2ae7bba5374e4bdee23c773 Mon Sep 17 00:00:00 2001 From: Hein Date: Tue, 13 Jan 2026 15:09:56 +0200 Subject: [PATCH] =?UTF-8?q?feat(spectypes):=20=E2=9C=A8=20enhance=20SqlNul?= =?UTF-8?q?l=20to=20support=20float=20and=20int=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add handling for float32 and float64 in Scan method. * Implement parsing for integer types in Scan and FromString methods. * Improve flexibility of SqlNull for various numeric inputs. --- pkg/spectypes/sql_types.go | 8 ++++++++ 1 file changed, 8 insertions(+) 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)