-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(database/gdb): json type field incorrect scanning to string slice attribute #4107
base: feat/v2.9.0
Are you sure you want to change the base?
Conversation
@gqcn @cyjaysong // 函数签名
// func RegisterDatabaseConvertFunc(driverName, columnType string, fn fieldConvertFunc)
gdb.RegisterDatabaseConvertFunc("mysql", "json", func(dest reflect.Value, src any) (err error) {
// 使用dest.Addr()是因为json.Unmarshal需要指针类型
dv := dest.Addr().Interface()
// src就是数据库给的数据
// dest是要赋值给go的结构体字段
switch dv.(type) {
case *[]string:
err = json.Unmarshal(src.([]byte), dv)
case *[]int64:
err = json.Unmarshal(src.([]byte), dv)
default:
err=fmt.Errorf("暂时不支从json类型反序列化到%T", dv)
}
return err
}) |
@gqcn You can use pr #4114 for such problems in the future. You don’t need to modify gf every time you encounter a type that is not supported. Just open the interface for custom type conversion. ORM only supports some common types by default. |
No description provided.