We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
go version go1.23.4 darwin/arm64
2.9.0
Option Yes
DROP TABLE IF EXISTS `proxy_param`; CREATE TABLE `proxy_param` ( `proxy_id` bigint NOT NULL, `recommend_ids` json DEFAULT NULL, `photos` json DEFAULT NULL, PRIMARY KEY (`proxy_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; INSERT INTO `proxy_param` (`proxy_id`, `recommend_ids`, `photos`) VALUES (1, '[584, 585]', 'null'); INSERT INTO `proxy_param` (`proxy_id`, `recommend_ids`, `photos`) VALUES (2, '[]', NULL); 模型映射为: type ProxyParam struct { ProxyId int64 `json:"proxyId" orm:"proxy_id" description:""` RecommendIds []int64 `json:"recommendIds" orm:"recommend_ids" description:""` Photos []string `json:"photos" orm:"photos" description:""` }
var proxyParamList []*entity.ProxyParam err := dao.ProxyParam.Ctx(context.Background()).Scan(&proxyParamList) fmt.Println(err) // nil for _, param := range proxyParamList { fmt.Printf("%+v\n", param) } //遍历打印机结果1: &{ProxyId:1 RecommendIds:[584 585] Photos:[null]}, 这里反序列化结果明显错误了,null为有效的json内容,虽然和数据库的NULL有所不同,但是 json的null 转为[]string 结果应该是 [] //遍历打印机结果2: &{ProxyId:2 RecommendIds:[] Photos:[]}
var proxyId int64 err := dao.ProxyParam.Ctx(context.Background()).Where("proxy_id", 1). Fields("proxy_id").Scan(&proxyId) fmt.Println(err) // element of parameter "pointer" for function Scan should type of struct/*struct/[]struct/[]*struc fmt.Println(proxyId) var proxyIds []int64 err := dao.ProxyParam.Ctx(context.Background()).Fields("proxy_id").Scan(&proxyIds) fmt.Println(err) // nil fmt.Println(proxyIds) // [0 0] 内容错误,正确值是[1 2] var recommendIds []int64 err := dao.ProxyParam.Ctx(context.Background()).Where("proxy_id", 1). Fields("recommend_ids").Scan(&recommendIds) fmt.Println(err) //nil, 没有错误 fmt.Println(recommendIds) //[0] 内容错误,正确值是[584 585]
得到的查询结果是错误
正确的查询结果
The text was updated successfully, but these errors were encountered:
package main import ( "context" "fmt" _ "github.com/gogf/gf/contrib/drivers/mysql/v2" _ "github.com/gogf/gf/contrib/nosql/redis/v2" "github.com/gogf/gf/v2/frame/g" ) func main() { ctx := context.Background() _, _ = g.DB().Exec(ctx, "DROP TABLE IF EXISTS proxy_param") _, _ = g.DB().Exec(ctx, `CREATE TABLE proxy_param ( proxy_id bigint NOT NULL, recommend_ids json DEFAULT NULL, photos json DEFAULT NULL, PRIMARY KEY (proxy_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci`) _, _ = g.DB().Exec(ctx, `INSERT INTO proxy_param (proxy_id, recommend_ids, photos) VALUES (1, '[584, 585]', 'null')`) _, _ = g.DB().Exec(ctx, `INSERT INTO proxy_param (proxy_id, recommend_ids, photos) VALUES (2, '[]', NULL)`) type ProxyParam struct { ProxyId int64 `json:"proxyId" orm:"proxy_id" description:""` RecommendIds []int64 `json:"recommendIds" orm:"recommend_ids" description:""` Photos []string `json:"photos" orm:"photos" description:""` } var proxyParamList []*ProxyParam err := g.DB().Model("proxy_param").Ctx(ctx).Scan(&proxyParamList) fmt.Println(err) // nil for _, param := range proxyParamList { fmt.Printf("%+v\n", param) } //遍历打印机结果1: &{ProxyId:1 RecommendIds:[584 585] Photos:[null]}, 这里反序列化结果明显错误了,null为有效的json内容,虽然和数据库的NULL有所不同,但是 json的null 转为[]string 结果应该是 [] //遍历打印机结果2: &{ProxyId:2 RecommendIds:[] Photos:[]} var proxyId int64 err = g.DB().Model("proxy_param").Ctx(ctx).Where("proxy_id", 1). Fields("proxy_id").Scan(&proxyId) fmt.Println(err) // element of parameter "pointer" for function Scan should type of struct/*struct/[]struct/[]*struc fmt.Println(proxyId) // 0 var proxyIds []int64 err = g.DB().Model("proxy_param").Ctx(ctx).Fields("proxy_id").Scan(&proxyIds) fmt.Println(err) // nil fmt.Println(proxyIds) // [0 0] 内容错误,正确值是[1 2] var recommendIds []int64 err = g.DB().Model("proxy_param").Ctx(ctx).Where("proxy_id", 1). Fields("recommend_ids").Scan(&recommendIds) fmt.Println(err) //nil, 没有错误 fmt.Println(recommendIds) //[0] 内容错误,正确值是[584 585] } ``
Sorry, something went wrong.
Let me see.
gqcn
No branches or pull requests
Go version
go version go1.23.4 darwin/arm64
GoFrame version
2.9.0
Can this bug be reproduced with the latest release?
Option Yes
What did you do?
What did you see happen?
得到的查询结果是错误
What did you expect to see?
正确的查询结果
The text was updated successfully, but these errors were encountered: