温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

go xorm生成mysql的结构体实例分析

发布时间:2022-03-17 08:57:01 阅读:295 作者:iii 栏目:开发技术
亿速云mysql数据库,读写分离,安全稳定,弹性扩容,低至0.3元/天!! 点击查看>>

本篇内容介绍了“go xorm生成mysql的结构体实例分析”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

网上很多资源都说是xorm reverse mysql "root:123456@tcp(127.0.0.1:3306)/users?charset=utf8" ./

执行后报错:2022/03/16 15:00:53 [Error] reverse.go:196 Unknown colType INT UNSIGNED

go xorm生成mysql的结构体实例分析

实际上原有的xorm 已经不能用了,现在要这么用:

go get xorm.io/reverse

然后进入到GOPATH下面的bin目录

go xorm生成mysql的结构体实例分析

vi custom.yml,用来配置连接数据库的信息:

kind: reverse
name: users
source:
  database: mysql
  conn_str: 'root:123456@tcp(127.0.0.1:3306)/users?parseTime=true'
targets:
- type: codes
  language: golang
  output_dir: ./testoutput

执行:./reverse -f custom.yml

然后进入testoutput/ 目录下,就生成好了models.go文件:

package models

type UserInfo struct {
        Id         uint   `xorm:"not null pk autoincr comment('主键ID') UNSIGNED INT"`
        Name       string `xorm:"not null default '' comment('姓名') VARCHAR(50)"`
        Avatar     string `xorm:"not null default '' comment('头像') VARCHAR(255)"`
        Birthday   string `xorm:"not null default '' comment('出生日期') VARCHAR(50)"`
        Sex        int    `xorm:"not null default 0 comment('性别:0未知,1男,2女') TINYINT(1)"`
        City       string `xorm:"not null default '' comment('所在城市') VARCHAR(50)"`
        Introduce  string `xorm:"comment('自我介绍') TEXT"`
        Status     int    `xorm:"not null default 0 comment('状态:0正常,1禁用') TINYINT(1)"`
        CreateTime uint   `xorm:"not null default 0 comment('创建时间') UNSIGNED INT"`
        UpdateTime uint   `xorm:"not null default 0 comment('最后修改时间') UNSIGNED INT"`
        DeleteTime uint   `xorm:"not null default 0 comment('删除时间') UNSIGNED INT"`
}

go xorm生成mysql的结构体实例分析

“go xorm生成mysql的结构体实例分析”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

亿速云「云数据库 MySQL」免部署即开即用,比自行安装部署数据库高出1倍以上的性能,双节点冗余防止单节点故障,数据自动定期备份随时恢复。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×