Go xorm工具生成数据库表结构的go model
程序员文章站
2022-03-15 19:33:20
...
详情:cmd工具
go get github.com/go-xorm/xorm
go get github.com/lib/pq
cd到安装路径
1.cd G:\go_workspace\GOPATH\src\github.com\go-xorm\cmd\xorm
2.g:
3.go build //这样就生成了xorm.exe
3.xorm reverse postgres “dbname=test sslmode=disable user=postgres password=123” templates/goxorm
执行完毕,会在当前路径cd G:\go_workspace\GOPATH\src\github.com\go-xorm\cmd\xorm下的model文件夹里
出现test数据库中,所有表的go model
user.go
package model
import (
"time"
)
type User struct {
Id int `xorm:"not null pk autoincr INTEGER"`
Name string `xorm:"VARCHAR(20)"`
Created time.Time `xorm:"default 'now()' DATETIME"`
ClassId int `xorm:"default 1 INTEGER"`
}
class.go
package model
type Class struct {
Id int `xorm:"not null pk autoincr INTEGER"`
Name string `xorm:"VARCHAR(20)"`
}