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

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

vi custom.yml,用來(lái)配置連接數(shù)據(jù)庫(kù)的信息:
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
然后進(jìn)入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)建時(shí)間') UNSIGNED INT"`
UpdateTime uint `xorm:"not null default 0 comment('最后修改時(shí)間') UNSIGNED INT"`
DeleteTime uint `xorm:"not null default 0 comment('刪除時(shí)間') UNSIGNED INT"`
}
到此這篇關(guān)于go xorm生成mysql的結(jié)構(gòu)體的文章就介紹到這了,更多相關(guān)go xorm結(jié)構(gòu)體內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Go語(yǔ)言實(shí)戰(zhàn)之詳細(xì)掌握正則表達(dá)式的應(yīng)用與技巧
正則表達(dá)式是一種從左到右與主題字符串匹配的模式,正則表達(dá)式用于替換字符串中的文本,驗(yàn)證表單,基于模式匹配從字符串中提取子字符串等等,這篇文章主要給大家介紹了關(guān)于Go語(yǔ)言實(shí)戰(zhàn)之詳細(xì)掌握正則表達(dá)式的應(yīng)用與技巧,需要的朋友可以參考下2023-12-12
Golang中常見(jiàn)的三種并發(fā)控制方式使用小結(jié)
這篇文章主要為大家詳細(xì)介紹了如何對(duì)goroutine并發(fā)行為的控制,在Go中最常見(jiàn)的有三種方式:sync.WaitGroup、channel和Context,下面我們就來(lái)看看他們的具體使用吧2024-01-01
一文搞懂Go語(yǔ)言標(biāo)準(zhǔn)庫(kù)strconv
strconv包實(shí)現(xiàn)了基本數(shù)據(jù)類型和其字符串表示的相互轉(zhuǎn)換,本文主要介紹Go語(yǔ)言標(biāo)準(zhǔn)庫(kù)strconv,想要學(xué)習(xí)strconv標(biāo)準(zhǔn)庫(kù)的可以了解一下2023-04-04
golang結(jié)構(gòu)化日志log/slog包之LogValuer的用法簡(jiǎn)介
這篇文章主要為大家詳細(xì)介紹了golang結(jié)構(gòu)化日志log/slog包中 LogValuer 和日志記錄函數(shù)的正確包裝方法,感興趣的小伙伴可以跟隨小編一起了解一下2023-10-10
GO中使用谷歌GEMINI模型任務(wù)代碼實(shí)例
這篇文章主要為大家介紹了GO中使用谷歌GEMINI模型任務(wù)代碼實(shí)例探究,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2024-01-01

