diff --git a/app/community/rpc/internal/logic/helpers.go b/app/community/rpc/internal/logic/helpers.go index d134634..09d672f 100644 --- a/app/community/rpc/internal/logic/helpers.go +++ b/app/community/rpc/internal/logic/helpers.go @@ -10,7 +10,7 @@ import ( func toTextArray(s []string) types.TextArray { if len(s) == 0 { - return types.TextArray{Valid: true} + return types.TextArray{Elements: []string{}, Valid: true} } return types.TextArray{ Elements: s, diff --git a/pkg/types/TextArray.go b/pkg/types/TextArray.go index d34707c..3bedd2e 100644 --- a/pkg/types/TextArray.go +++ b/pkg/types/TextArray.go @@ -13,6 +13,13 @@ type TextArray pgtype.Array[string] func (s *TextArray) Scan(src any) error { logx.Infof("scan src=%+v", src) + if src == nil { + s.Elements = []string{} + s.Dims = nil + s.Valid = true + return nil + } + var strSrc string switch v := src.(type) { case string: @@ -37,5 +44,8 @@ func (s *TextArray) Scan(src any) error { } func (s TextArray) Value() (driver.Value, error) { + if s.Elements == nil { + return []string{}, nil + } return s.Elements, nil }