Home > Database > Mysql Tutorial > body text

Go xorm generates structure example analysis of mysql

WBOY
Release: 2023-05-30 16:35:15
forward
1552 people have browsed it

Many resources on the Internet say that it is xorm reverse mysql "root:123456@tcp(127.0.0.1:3306)/users?charset=utf8" ./

Error after execution: 2022/03 /16 15:00:53 [Error] reverse.go:196 Unknown colType INT UNSIGNED

Go xorm generates structure example analysis of mysql

In fact, the original xorm can no longer be used, now it is like this Use:

go get xorm.io/reverse

and then enter the bin directory under GOPATH

Go xorm generates structure example analysis of mysql

vi custom.yml, used to configure the information to connect to the database:

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
Copy after login

Execute: ./reverse -f custom.yml

Then enter the testoutput/ directory to generate models.go File:

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"`
}
Copy after login

Go xorm generates structure example analysis of mysql

The above is the detailed content of Go xorm generates structure example analysis of mysql. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!