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,用来配置连接数据库的信息:

  1. kind: reversename: userssource:  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文件:

  1. package modelstype 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的结构体实例分析的详细内容,更多请关注【创想鸟】其它相关文章!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

点点赞赏,手留余香

给TA打赏
共0人
还没有人赞赏,快来当第一个赞赏的人吧!
    数据库

    Mysql8怎么创建用户及赋权

    2025-2-18 8:24:43

    数据库

    如何用Python操作MySQL

    2025-2-18 8:24:54

    0 条回复 A文章作者 M管理员
    欢迎您,新朋友,感谢参与互动!
      暂无讨论,说说你的看法吧
    个人中心
    购物车
    优惠劵
    今日签到
    私信列表
    搜索