详解xorm怎么自动生成model
时间:2021-11-04
来源:互联网
标签:
今天PHP爱好者给大家带来本文由go语言教程栏目给大家介绍关于xorm自动生成mode的方法 ,希望对需要的朋友有所帮助!
xorm自动生成model文件
进入项目根目录
luwei@luweideMacBook-Pro-2 go-simple-task % pwd/Users/myself/Golang/common_project/src/go-simple-task
luwei@luweideMacBook-Pro-2 go-simple-task % ls
Dockerfile go-simple-task go.mod go.sum logic logs main.go model models overall serv templates tool
luwei@luweideMacBook-Pro-2 go-simple-task %
如果没有go-sql-driver/mysql就先安装
go get -u github.com/go-sql-driver/mysql
安装xorm,在cmd命令行下
go get github.com/go-xorm/xorm
再安装xorm的cmd命令工具
go get github.com/go-xorm/cmd/xorm
安装 cmd 报错处理
luwei@luweideMacBook-Pro-2 go-simple-task % go get github.com/go-xorm/cmd/xorm
# github.com/go-xorm/cmd/xorm
../../pkg/mod/github.com/go-xorm/cmd/[email protected]/dump.go:45:26: cannot use "github.com/go-xorm/core".LOG_UNKNOWN (type "github.com/go-xorm/core".LogLevel) as type "xorm.io/core".LogLevel in argument to engine.Logger().SetLevel
../../pkg/mod/github.com/go-xorm/cmd/[email protected]/reverse.go:246:34: cannot use tables (type []*"xorm.io/core".Table) as type []*"github.com/go-xorm/core".Table in argument to langTmpl.GenImports
../../pkg/mod/github.com/go-xorm/cmd/[email protected]/reverse.go:254:18: cannot use table (type *"xorm.io/core".Table) as type *"github.com/go-xorm/core".Table in append
../../pkg/mod/github.com/go-xorm/cmd/[email protected]/reverse.go:291:26: cannot use table (type *"xorm.io/core".Table) as type *"github.com/go-xorm/core".Table in slice literal
../../pkg/mod/github.com/go-xorm/cmd/[email protected]/shell.go:60:26: cannot use "github.com/go-xorm/core".LOG_UNKNOWN (type "github.com/go-xorm/core".LogLevel) as type "xorm.io/core".LogLevel in argument to engine.Logger().SetLevel
../../pkg/mod/github.com/go-xorm/cmd/[email protected]/source.go:45:26: cannot use "github.com/go-xorm/core".LOG_UNKNOWN (type "github.com/go-xorm/core".LogLevel) as type "xorm.io/core".LogLevel in argument to engine.Logger().SetLevel
luwei@luweideMacBook-Pro-2 go-simple-task %
跳出项目目录执行,完了再跳回去
luwei@luweideMacBook-Pro-2 go-simple-task % cd ../luwei@luweideMacBook-Pro-2 src % go get github.com/go-xorm/cmd/xorm
luwei@luweideMacBook-Pro-2 src %
在项目目录下建立 templates/goxorm 文件夹
这个文件下建立config和struct.go.tpl文件.
模板内容可以根据你自己的需要修改
config内容如下
lang=go
genJson=1prefix=struct.go.tpl内容如下
package {{.Models}}{{$ilen := len .Imports}}{{if gt $ilen 0}}import (
{{range .Imports}}"{{.}}"{{end}}){{end}}{{range .Tables}}type {{Mapper .Name}} struct {{{$table := .}}{{range .ColumnsSeq}}{{$col := $table.GetColumn .}} {{Mapper $col.Name}} {{Type $col}} {{Tag $table $col}}{{end}}}{{end}}
最后执行命令
程序会在当前目录下生成models文件夹,并在models文件夹中生成go文件
xorm reverse mysql root:root@/fox?charset=utf8 templates/goxorm
执行报错
luwei@luweideMacBook-Pro-2 go-simple-task % xorm reverse mysql root:123456@/bubble?charset=utf8 templates/goxorm
zsh: no matches found: root:123456@/bubble?charset=utf8
解决方案
vim ~/.zshrc
在~/.zshrc中加入:
setopt no_nomatch
检查一下
luwei@luweideMacBook-Pro-2 go-simple-task % cat ~/.zshrc
source ~/.bash_profileexport GOPROXY=https://goproxy.io,direct
setopt no_nomatch最后执行
source ~/.zshrc
再次执行
luwei@luweideMacBook-Pro-2 go-simple-task % xorm reverse mysql root:123456@/bubble?charset=utf8 templates/goxorm
luwei@luweideMacBook-Pro-2 go-simple-task %
剩下就是把models里的内容赋值到model 对应的model里面了
以上就是详解xorm怎么自动生成model的详细内容,更多请关注php爱好者其它相关文章!
-
Connection reset是什么意思-Connection reset原因分析和解决方案 时间:2025-09-16
-
百度网盘不限速的方法(官方推荐) 时间:2025-09-16
-
Visual Studio Code下载和安装教程 怎么改成中文? 时间:2025-09-16
-
浏览器显示"您的连接不是私密连接"是什么意思?原因分析及解决方法 时间:2025-09-16
-
ChromeDriver下载地址在哪 ChromeDriver安装及配置教程 时间:2025-09-16
-
Python中syntaxerror:invalid syntax错误的原因及解决方法 时间:2025-09-16
今日更新
-
剃须刀是什么梗揭秘网红暗号真实含义 看完秒懂年轻人新潮流
阅读:18
-
替别人尴尬的梗是什么梗?网友直呼代入感太强脚趾抠地!
阅读:18
-
替身梗是什么梗?揭秘网络热词背后的替身文学与搞笑模仿文化,轻松get流行趋势!
阅读:18
-
替身攻击是什么梗?揭秘JOJO中炫酷超能力的网络爆火梗解析
阅读:18
-
替身是什么梗揭秘网络热词背后的搞笑真相
阅读:18
-
重返未来:1999翻覆之舟-翻覆之舟17怎么通关配队
阅读:18
-
时空中的绘旅人周年盛典-限时累充活动即将开启
阅读:18
-
无限暖暖9月下半奇迹之冠-后四关巅峰赛过关建议
阅读:18
-
以闪亮之名复刻追光活动-四星套装纪元余音预览开放
阅读:18
-
时空中的绘旅人全新卡面-叶瑄SSR·溯时契即将上线
阅读:18