gf
gf copied to clipboard
2.6.3 nil and empty arrays should not be ignored when inserting and updating JSON fields
数据表有JSON字段类型时,保存数据,数据为空数组时,2.6版本会忽略此字段。但MYSQL中,JSON字段是必须赋值的。就造成很大困扰。
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
When the data table has a JSON field type, save the data. When the data is an empty array, version 2.6 will ignore this field. But in MYSQL, JSON fields must be assigned values. It caused a lot of trouble.
这些BUG什么时候能修复呢
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
When will these bugs be fixed?
比如:
dao.User.Ctx(ctx).Insert(do.User{
Id:1,
Name:"小李",
Files:[]string{},
})
这时,生成的SQL语句为:insert into user (id,name) values(1,"小李") 没有files字段。但files字段是JSON字段,必须赋值。所以SQL报错。
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
For example: dao.User.Ctx(ctx).Insert(do.User{ Id:1, Name:"Xiao Li", Files:[]string{}, })
At this time, the generated SQL statement is: insert into user (id, name) values (1, "Xiao Li") without the files field. But the files field is a JSON field and must be assigned a value. So SQL reports an error.
这个地方很诡异,
如何判断这个json是[]
或 {}
,代码如何赋值呢?
根据结构体匹配字段的类型,再赋值默认值吗?
是不是可以在数据库字段设置默认值处理
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
This place is very weird,
How to determine whether this json is []
or {}
, and how to assign the value in the code?
Should a default value be assigned based on the type of the field matched in the structure?
Is it possible to set default value processing in database fields?