处理 text NULL 字段

This commit is contained in:
2024-11-07 05:31:30 +08:00
parent 37156568ed
commit 0fef776ece
2 changed files with 52 additions and 0 deletions

View File

@@ -87,6 +87,11 @@ type TextList []struct {
}
func (a *TextList) Scan(value interface{}) error {
// 如果数据库中的值为NULL则返回nil
if value == nil || len(value.([]byte)) == 0 {
*a = TextList{}
return nil
}
return json.Unmarshal(value.([]byte), a)
}