fix: 修复社区帖子空数组处理
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
func toTextArray(s []string) types.TextArray {
|
func toTextArray(s []string) types.TextArray {
|
||||||
if len(s) == 0 {
|
if len(s) == 0 {
|
||||||
return types.TextArray{Valid: true}
|
return types.TextArray{Elements: []string{}, Valid: true}
|
||||||
}
|
}
|
||||||
return types.TextArray{
|
return types.TextArray{
|
||||||
Elements: s,
|
Elements: s,
|
||||||
|
|||||||
@@ -13,6 +13,13 @@ type TextArray pgtype.Array[string]
|
|||||||
|
|
||||||
func (s *TextArray) Scan(src any) error {
|
func (s *TextArray) Scan(src any) error {
|
||||||
logx.Infof("scan src=%+v", src)
|
logx.Infof("scan src=%+v", src)
|
||||||
|
if src == nil {
|
||||||
|
s.Elements = []string{}
|
||||||
|
s.Dims = nil
|
||||||
|
s.Valid = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var strSrc string
|
var strSrc string
|
||||||
switch v := src.(type) {
|
switch v := src.(type) {
|
||||||
case string:
|
case string:
|
||||||
@@ -37,5 +44,8 @@ func (s *TextArray) Scan(src any) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s TextArray) Value() (driver.Value, error) {
|
func (s TextArray) Value() (driver.Value, error) {
|
||||||
|
if s.Elements == nil {
|
||||||
|
return []string{}, nil
|
||||||
|
}
|
||||||
return s.Elements, nil
|
return s.Elements, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user