聊聊go xorm生成mysql的結構體問題
網(wǎng)上很多資源都說是xorm reverse mysql "root:123456@tcp(127.0.0.1:3306)/users?charset=utf8" ./
執(zhí)行后報錯:2022/03/16 15:00:53 [Error] reverse.go:196 Unknown colType INT UNSIGNED

實際上原有的xorm 已經不能用了,現(xiàn)在要這么用:
go get xorm.io/reverse
然后進入到GOPATH下面的bin目錄

vi custom.yml,用來配置連接數(shù)據(jù)庫的信息:
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
執(zhí)行:./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('狀態(tài):0正常,1禁用') TINYINT(1)"`
CreateTime uint `xorm:"not null default 0 comment('創(chuàng)建時間') 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結構體內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
golang結構化日志log/slog包之LogValuer的用法簡介
這篇文章主要為大家詳細介紹了golang結構化日志log/slog包中 LogValuer 和日志記錄函數(shù)的正確包裝方法,感興趣的小伙伴可以跟隨小編一起了解一下2023-10-10

