聊聊go xorm生成mysql的結(jié)構(gòu)體問題
網(wǎng)上很多資源都說是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,用來配置連接數(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)文章
Golang實(shí)現(xiàn)Biginteger大數(shù)計(jì)算實(shí)例詳解
這篇文章主要為大家介紹了Golang實(shí)現(xiàn)Biginteger大數(shù)計(jì)算實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07golang?waitgroup輔助并發(fā)控制使用場(chǎng)景和方法解析
Golang?提供了簡(jiǎn)潔的?go?關(guān)鍵字來讓開發(fā)者更容易的進(jìn)行并發(fā)編程,同時(shí)也提供了?WaitGroup?對(duì)象來輔助并發(fā)控制,今天我們就來分析下?WaitGroup?的使用方法,順便瞧一瞧它的底層源碼2023-09-09一文帶你了解Go語言標(biāo)準(zhǔn)庫(kù)math和rand的常用函數(shù)
這篇文章主要為大家詳細(xì)介紹了Go語言標(biāo)準(zhǔn)庫(kù)math和rand中的常用函數(shù),文中的示例代碼講解詳細(xì), 對(duì)我們學(xué)習(xí)Go語言有一定的幫助,感興趣的小伙伴可以了解一下2022-12-12試了下Golang實(shí)現(xiàn)try catch的方法
雖然在使用Golang的時(shí)候發(fā)現(xiàn)沒有try catch這種錯(cuò)誤處理機(jī)制但是想一想golang作為一門優(yōu)雅的語言,似乎也是情理之中。那么夠怎么捕獲異常呢,本文就來介紹一下2021-07-07gtoken替換jwt實(shí)現(xiàn)sso登錄的排雷避坑
這篇文章主要為大家介紹了gtoken替換jwt實(shí)現(xiàn)sso登錄的排雷避坑,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06