兼容使用pg数据库,contacts字段json格式无法转换的问题 (#868)

This commit is contained in:
张哲铭 2022-02-15 17:58:33 +08:00 committed by GitHub
parent 6a3a630759
commit 37421dd56a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -12,9 +12,16 @@ type JSONArr json.RawMessage
// 实现 sql.Scanner 接口Scan 将 value 扫描至 Jsonb
func (j *JSONObj) Scan(value interface{}) error {
// 判断是不是byte类型
bytes, ok := value.([]byte)
if !ok {
return errors.New(fmt.Sprint("Failed to unmarshal JSONB value:", value))
// 判断是不是string类型
strings, ok := value.(string)
if !ok {
return errors.New(fmt.Sprint("Failed to unmarshal JSONB value:", value))
}
// string类型转byte[]
bytes = []byte(strings)
}
result := json.RawMessage{}