From defe27549b7f42ca7e9653b60c6da407fcbd8315 Mon Sep 17 00:00:00 2001 From: Hein Date: Tue, 27 Jan 2026 17:35:13 +0200 Subject: [PATCH] =?UTF-8?q?feat(sql):=20=E2=9C=A8=20Improve=20base64=20han?= =?UTF-8?q?dling=20in=20SqlNull=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Refactor base64 encoding and decoding checks for []byte types. * Simplify type assertions using if statements instead of switch cases. --- pkg/spectypes/sql_types.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pkg/spectypes/sql_types.go b/pkg/spectypes/sql_types.go index 1d008d1..f9a81d6 100644 --- a/pkg/spectypes/sql_types.go +++ b/pkg/spectypes/sql_types.go @@ -64,8 +64,7 @@ func (n *SqlNull[T]) Scan(value any) error { // Check if T is []byte, and decode base64 if applicable // Do this BEFORE trying sql.Null to ensure base64 is handled var zero T - switch any(zero).(type) { - case []byte: + if _, ok := any(zero).([]byte); ok { // For []byte types, try to decode from base64 var strVal string switch v := value.(type) { @@ -182,10 +181,9 @@ func (n SqlNull[T]) MarshalJSON() ([]byte, error) { } // Check if T is []byte, and encode to base64 - switch v := any(n.Val).(type) { - case []byte: + if _, ok := any(n.Val).([]byte); ok { // Encode []byte as base64 - encoded := base64.StdEncoding.EncodeToString(v) + encoded := base64.StdEncoding.EncodeToString(any(n.Val).([]byte)) return json.Marshal(encoded) } @@ -202,8 +200,7 @@ func (n *SqlNull[T]) UnmarshalJSON(b []byte) error { // Check if T is []byte, and decode from base64 var val T - switch any(val).(type) { - case []byte: + if _, ok := any(val).([]byte); ok { // Unmarshal as string first (JSON representation) var s string if err := json.Unmarshal(b, &s); err == nil {