Skip to content
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

mysql 模型字段与数据库类型struct->json类型的支持 #911

Open
shuiziliu7788 opened this issue Mar 2, 2021 · 6 comments
Open

Comments

@shuiziliu7788
Copy link

mysql 模型字段与数据库类型struct->json类型的支持

@flycash
Copy link
Collaborator

flycash commented Mar 2, 2021

什么意思?

@shuiziliu7788
Copy link
Author

什么意思?

mysql json 类型映射的时候不支持通过bee generate自动化的生成代码,现在改修的项目有大量的json类型
Name string orm:"type(json);size(1024)"也有问题,可不可支持mysql 的json类型的对应,可以修改成对应map类型或者自定义struct

@flycash
Copy link
Collaborator

flycash commented Mar 3, 2021

哦哦,你是指字段里面存储JSON字符串是吧?这是计划中的事情,之前有一个外国开发来了一个PR,不过无法通过UT,还有很多问题,后面他就自己关了。

你可以自己定义Fielder来扩展。不过目测有点难度……

@flycash
Copy link
Collaborator

flycash commented Mar 3, 2021

等我这段时间加完班腾出手来搞搞

@shuiziliu7788
Copy link
Author

测试model

type GoodsImages []string
func (e *GoodsImages) FieldType() int {
  return orm.TypeJSONField
}
type Skus struct {
  GoodsImages GoodsImages `orm:"type(json);description(商品图片)"`
}

mysql 自动创建表时生成的mysql语法:goods_images varchar(255) NOT NULL DEFAULT '{}'
mysql 自动转换成varchar类型,mysql的json类型默认值只能为null

@flycash
Copy link
Collaborator

flycash commented Mar 14, 2021

要等等等一会了……最近巨忙……

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants