增加新特性,并修复一些问题
This commit is contained in:
@@ -38,6 +38,7 @@ is_out_func : true # Whether to output function
|
||||
is_url_tag : true # Whether to mark web or not
|
||||
is_foreign_key : true # Whether to mark foreign key or not
|
||||
is_gui : false # Whether to operate on gui
|
||||
is_table_name : false # Whether to out GetTableName function
|
||||
|
||||
mysql_info :
|
||||
host : "127.0.0.1"
|
||||
@@ -198,5 +199,3 @@ go generate
|
||||
## Stargazers over time
|
||||
|
||||
[](https://starchart.cc/xxjwxc/gormt)
|
||||
|
||||
## 20200228 llllancelot foked
|
||||
|
||||
@@ -42,6 +42,7 @@ is_out_func : true # 是否输出 快捷函数
|
||||
is_url_tag : true # 是否打web标记
|
||||
is_foreign_key : true # 是否导出外键关联
|
||||
is_gui : false # 是否ui模式显示
|
||||
is_table_name : false # 是否直接生成表名函数
|
||||
mysql_info:
|
||||
host : 127.0.0.1
|
||||
port : 3306
|
||||
|
||||
@@ -11,6 +11,7 @@ is_out_func : true # 是否输出 快捷函数
|
||||
is_url_tag : true # 是否打web标记
|
||||
is_foreign_key : true # 是否导出外键关联
|
||||
is_gui : false # 是否ui模式显示
|
||||
is_table_name : false # 是否直接生成表名函数
|
||||
mysql_info:
|
||||
host : 127.0.0.1
|
||||
port : 3306
|
||||
|
||||
@@ -3,6 +3,7 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/xxjwxc/public/tools"
|
||||
|
||||
@@ -21,6 +22,8 @@ var foreignKey bool
|
||||
var funcKey bool
|
||||
var ui bool
|
||||
var urlTag string
|
||||
var tableList string
|
||||
var outFileName string
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "main",
|
||||
@@ -72,6 +75,11 @@ func init() {
|
||||
rootCmd.PersistentFlags().StringVarP(&urlTag, "url", "l", "", "url标签(json,url)")
|
||||
rootCmd.MarkFlagRequired("url tag")
|
||||
|
||||
rootCmd.PersistentFlags().StringVarP(&tableList, "tablelist", "t", "", "目标table列表,以','隔开")
|
||||
rootCmd.MarkFlagRequired("table list")
|
||||
|
||||
rootCmd.Flags().StringVar(&outFileName, "outfilename", "", "输出文件名,默认以数据库名称命名")
|
||||
|
||||
rootCmd.Flags().IntVar(&mysqlInfo.Port, "port", 3306, "端口号")
|
||||
}
|
||||
|
||||
@@ -111,6 +119,19 @@ func MergeMysqlDbInfo() {
|
||||
if len(urlTag) > 0 {
|
||||
config.SetURLTag(urlTag)
|
||||
}
|
||||
if len(tableList) > 0 {
|
||||
m := make(map[string]struct{})
|
||||
for _, v := range strings.Split(tableList, ",") {
|
||||
m[v] = struct{}{}
|
||||
}
|
||||
config.SetTableList(m)
|
||||
}
|
||||
if len(outFileName) > 0 {
|
||||
if !strings.HasSuffix(outFileName, ".go") {
|
||||
outFileName += ".go"
|
||||
}
|
||||
config.SetOutFileName(outFileName)
|
||||
}
|
||||
|
||||
config.SetMysqlDbInfo(&tmp)
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@ type Config struct {
|
||||
IsOutSQL bool `yaml:"is_out_sql"`
|
||||
IsOutFunc bool `yaml:"is_out_func"`
|
||||
IsGUI bool `yaml:"is_gui"` //
|
||||
IsTableName bool `yaml:"is_table_name"`
|
||||
TableList map[string]struct{} `yaml:"-"`
|
||||
OutFileName string `yaml:"-"`
|
||||
}
|
||||
|
||||
// MysqlDbInfo mysql database information. mysql 数据库信息
|
||||
@@ -132,6 +135,32 @@ func SetIsGUI(b bool) {
|
||||
_map.IsGUI = b
|
||||
}
|
||||
|
||||
// GetIsTableName if is table name .
|
||||
func GetIsTableName() bool {
|
||||
return _map.IsTableName
|
||||
}
|
||||
|
||||
// SetIsTableName if is table name .
|
||||
func SetIsTableName(b bool) {
|
||||
_map.IsTableName = b
|
||||
}
|
||||
|
||||
func SetTableList(m map[string]struct{}) {
|
||||
_map.TableList = m
|
||||
}
|
||||
|
||||
func GetTableList() map[string]struct{} {
|
||||
return _map.TableList
|
||||
}
|
||||
|
||||
func SetOutFileName(f string) {
|
||||
_map.OutFileName = f
|
||||
}
|
||||
|
||||
func GetOutFileName() string {
|
||||
return _map.OutFileName
|
||||
}
|
||||
|
||||
// GetURLTag get url tag.
|
||||
func GetURLTag() string {
|
||||
if _map.URLTag != "json" && _map.URLTag != "url" {
|
||||
|
||||
@@ -3,8 +3,6 @@ package config
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/xxjwxc/public/dev"
|
||||
"github.com/xxjwxc/public/tools"
|
||||
@@ -20,65 +18,33 @@ type CfgBase struct {
|
||||
IsDev bool `json:"is_dev" yaml:"is_dev"` // Is it a development version?是否是开发版本
|
||||
}
|
||||
|
||||
var _map = Config{
|
||||
CfgBase: CfgBase{
|
||||
IsDev: false,
|
||||
},
|
||||
MySQLInfo: MysqlDbInfo{
|
||||
Host: "127.0.0.1",
|
||||
Port: 3306,
|
||||
Username: "root",
|
||||
Password: "root",
|
||||
Database: "test",
|
||||
},
|
||||
OutDir: "./model",
|
||||
URLTag: "json",
|
||||
Language: "中 文",
|
||||
DbTag: "gorm",
|
||||
Simple: false,
|
||||
IsWEBTag: false,
|
||||
SingularTable: true,
|
||||
IsForeignKey: true,
|
||||
IsOutSQL: false,
|
||||
IsOutFunc: true,
|
||||
IsGUI: false,
|
||||
}
|
||||
|
||||
var configPath string
|
||||
var _map = Config{}
|
||||
|
||||
func init() {
|
||||
configPath = path.Join(tools.GetModelPath(), "config.yml")
|
||||
onInit()
|
||||
dev.OnSetDev(_map.IsDev)
|
||||
}
|
||||
|
||||
func onInit() {
|
||||
err := InitFile(configPath)
|
||||
path := tools.GetModelPath()
|
||||
err := InitFile(path + "/config.yml")
|
||||
if err != nil {
|
||||
fmt.Println("Load config file error: ", err.Error())
|
||||
fmt.Println("InitFile: ", err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// InitFile default value from file .
|
||||
func InitFile(filename string) error {
|
||||
if _, e := os.Stat(filename); e != nil {
|
||||
fmt.Println("init default config file: ", filename)
|
||||
if err := SaveToFile(); err == nil {
|
||||
fmt.Println("done,please restart.")
|
||||
} else {
|
||||
fmt.Println("shit,fail", err)
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
bs, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := yaml.Unmarshal(bs, &_map); err != nil {
|
||||
fmt.Println("read config file error: ", err.Error())
|
||||
fmt.Println("read toml error: ", err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -106,8 +72,9 @@ func SaveToFile() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tools.WriteFile(configPath, []string{
|
||||
tools.WriteFile(tools.GetModelPath()+"/config.yml", []string{
|
||||
string(d),
|
||||
}, true)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,14 +4,12 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/xxjwxc/public/tools"
|
||||
|
||||
"github.com/xxjwxc/gormt/data/config"
|
||||
|
||||
"github.com/jroimartin/gocui"
|
||||
"github.com/xxjwxc/public/myclipboard"
|
||||
"github.com/xxjwxc/public/mycui"
|
||||
)
|
||||
|
||||
@@ -79,7 +77,7 @@ func mainLayout(g *gocui.Gui) error {
|
||||
// }
|
||||
}
|
||||
|
||||
if v, err := g.SetView(_viewDefine, division(maxX, uiPart[0]), 1, maxX-1, maxY-3); err != nil {
|
||||
if v, err := g.SetView(_viewDefine, division(maxX, uiPart[0]), 1, maxX-1, maxY-1); err != nil {
|
||||
if err != gocui.ErrUnknownView {
|
||||
return err
|
||||
}
|
||||
@@ -105,11 +103,6 @@ func nemuLayOut(g *gocui.Gui) {
|
||||
AddHandler(gocui.KeyArrowUp, menuDlg.prevButton).AddHandler(gocui.KeyArrowDown, menuDlg.nextButton).
|
||||
AddHandler(gocui.KeyEnter, enterSet).AddHandler(gocui.MouseLeft, enterSet))
|
||||
|
||||
maxX, maxY := g.Size() // division(maxY, uiPart[1])
|
||||
clipboardBtn = mycui.NewButton(g, _clipboardBtn, SLocalize(_clipboardBtn), division(maxX, uiPart[0])+2, maxY-3, 5).
|
||||
AddHandler(gocui.KeyEnter, enterClipboard).AddHandler(gocui.MouseLeft, enterClipboard)
|
||||
clipboardBtn.Draw()
|
||||
|
||||
menuDlg.Draw()
|
||||
menuFocusButton(g)
|
||||
}
|
||||
@@ -170,24 +163,6 @@ func addlog(g *gocui.Gui, str string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func enterClipboard(g *gocui.Gui, v *gocui.View) error {
|
||||
myclipboard.Set(copyInfo)
|
||||
|
||||
maxX, _ := g.Size()
|
||||
modal := mycui.NewModal(g, division(maxX, uiPart[0])+5, 10, division(maxX, uiPart[0])+35).
|
||||
SetTextColor(gocui.ColorRed).SetText("copy success \n 已 复 制 到 剪 切 板 ")
|
||||
modal.Mouse = true
|
||||
// modal.SetBgColor(gocui.ColorRed)
|
||||
_handle := func(g *gocui.Gui, v *gocui.View) error {
|
||||
modal.Close()
|
||||
return nil
|
||||
}
|
||||
modal.AddButton("ok", "OK", gocui.KeyEnter, _handle).AddHandler(gocui.MouseLeft, _handle)
|
||||
modal.Draw()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func enterRun(g *gocui.Gui, v *gocui.View) error {
|
||||
setlog(g, "run .... ing")
|
||||
generate(g, v)
|
||||
@@ -230,6 +205,8 @@ func enterSet(g *gocui.Gui, v *gocui.View) error {
|
||||
AddOptions(SLocalize("true"), SLocalize("false")).SetSelected(SLocalize(tools.AsString(config.GetIsForeignKey())))
|
||||
form.AddSelect("is_gui", SLocalize("is_gui"), formPart[0], formPart[2]).
|
||||
AddOptions(SLocalize("true"), SLocalize("false")).SetSelected(SLocalize(tools.AsString(config.GetIsGUI())))
|
||||
form.AddSelect("is_table_name", SLocalize("is_table_name"), formPart[0], formPart[2]).
|
||||
AddOptions(SLocalize("true"), SLocalize("false")).SetSelected(SLocalize(tools.AsString(config.GetIsTableName())))
|
||||
form.AddSelect("url_tag", SLocalize("url_tag"), formPart[0], formPart[2]).
|
||||
AddOptions("json", "url").SetSelected(tools.AsString(config.GetURLTag()))
|
||||
form.AddSelect("db_tag", SLocalize("db_tag"), formPart[0], formPart[2]).
|
||||
@@ -267,14 +244,12 @@ func buttonSave(g *gocui.Gui, v *gocui.View) error {
|
||||
port, err := strconv.Atoi(mp["db_port"])
|
||||
if err != nil {
|
||||
modal := mycui.NewModal(g, division(maxX, uiPart[0])+5, 10, division(maxX, uiPart[0])+35).SetTextColor(gocui.ColorRed).SetText("port error")
|
||||
|
||||
_handle := func(g *gocui.Gui, v *gocui.View) error {
|
||||
// modal.SetBgColor(gocui.ColorRed)
|
||||
modal.AddButton("ok", "OK", gocui.KeyEnter, func(g *gocui.Gui, v *gocui.View) error {
|
||||
modal.Close()
|
||||
form.SetCurrentItem(form.GetCurrentItem())
|
||||
return nil
|
||||
}
|
||||
// modal.SetBgColor(gocui.ColorRed)
|
||||
modal.AddButton("ok", "OK", gocui.KeyEnter, _handle).AddHandler(gocui.MouseLeft, _handle)
|
||||
})
|
||||
|
||||
modal.Draw()
|
||||
return nil
|
||||
@@ -294,18 +269,18 @@ func buttonSave(g *gocui.Gui, v *gocui.View) error {
|
||||
config.SetIsOutFunc(getBool(mp["is_out_func"]))
|
||||
config.SetForeignKey(getBool(mp["is_foreign_key"]))
|
||||
config.SetIsGUI(getBool(mp["is_gui"]))
|
||||
config.SetIsTableName(getBool(mp["is_table_name"]))
|
||||
config.SetURLTag(mp["url_tag"])
|
||||
config.SetDBTag(mp["db_tag"])
|
||||
config.SetLG(mp["language"])
|
||||
|
||||
config.SaveToFile()
|
||||
modal := mycui.NewModal(g, division(maxX, uiPart[0])+5, 10, division(maxX, uiPart[0])+35).SetText("save success")
|
||||
_handle := func(g *gocui.Gui, v *gocui.View) error {
|
||||
modal.AddButton("ok", "OK", gocui.KeyEnter, func(g *gocui.Gui, v *gocui.View) error {
|
||||
modal.Close()
|
||||
buttonCancel(g, v)
|
||||
return nil
|
||||
}
|
||||
modal.AddButton("ok", "OK", gocui.KeyEnter, _handle).AddHandler(gocui.MouseLeft, _handle)
|
||||
})
|
||||
modal.Draw()
|
||||
|
||||
return nil
|
||||
@@ -334,11 +309,10 @@ func showStruct(g *gocui.Gui, v *gocui.View) error {
|
||||
l = ""
|
||||
}
|
||||
|
||||
var out, out1 []string
|
||||
var out []string
|
||||
for _, v := range gPkg.Structs {
|
||||
if v.Name == l {
|
||||
out = v.GeneratesColor()
|
||||
out1 = v.Generates()
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -347,9 +321,6 @@ func showStruct(g *gocui.Gui, v *gocui.View) error {
|
||||
for _, v := range out {
|
||||
addlog(g, v)
|
||||
}
|
||||
|
||||
copyInfo = strings.Join(out1, "\n")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,10 @@ const (
|
||||
_viewDefine = "view"
|
||||
_run = "run"
|
||||
_set = "set"
|
||||
_clipboardBtn = "clipboardBtn"
|
||||
)
|
||||
|
||||
var (
|
||||
uiPart = []float32{4, 5} // x,y 对应列表
|
||||
uiPart = []float32{4, 3} // x,y 对应列表
|
||||
mainViewArr = []string{_menuDefine, _listDefine, _viewDefine} // 主菜单列表
|
||||
mainIndex = 0
|
||||
|
||||
@@ -34,9 +33,6 @@ type listDetails struct {
|
||||
btnList []*mycui.Button
|
||||
}
|
||||
|
||||
var clipboardBtn *mycui.Button
|
||||
var copyInfo string
|
||||
|
||||
var menuDlg *menuDetails
|
||||
var form *mycui.Form
|
||||
var gPkg genstruct.GenPackage
|
||||
|
||||
@@ -47,9 +47,6 @@ func addChinese() error {
|
||||
}, &i18n.Message{
|
||||
ID: "set",
|
||||
Other: "设 置 🛠 ",
|
||||
}, &i18n.Message{
|
||||
ID: "clipboardBtn",
|
||||
Other: "复 制 到 剪 切 板 ",
|
||||
}, &i18n.Message{
|
||||
ID: "out_dir",
|
||||
Other: " 输 出 目 录 :",
|
||||
@@ -89,6 +86,9 @@ func addChinese() error {
|
||||
}, &i18n.Message{
|
||||
ID: "is_gui",
|
||||
Other: " 界 面 模 式 :",
|
||||
}, &i18n.Message{
|
||||
ID: "is_table_name",
|
||||
Other: " 生 成 表 名 :",
|
||||
}, &i18n.Message{
|
||||
ID: "url_tag",
|
||||
Other: " web 标 签:",
|
||||
@@ -138,9 +138,6 @@ func addEnglish() error {
|
||||
}, &i18n.Message{
|
||||
ID: "set",
|
||||
Other: "Set 🛠 ",
|
||||
}, &i18n.Message{
|
||||
ID: "clipboardBtn",
|
||||
Other: "Copy to clipboard",
|
||||
}, &i18n.Message{
|
||||
ID: "out_dir",
|
||||
Other: "out dir:",
|
||||
@@ -180,6 +177,9 @@ func addEnglish() error {
|
||||
}, &i18n.Message{
|
||||
ID: "is_gui",
|
||||
Other: "is show gui:",
|
||||
}, &i18n.Message{
|
||||
ID: "is_table_name",
|
||||
Other: "is table name:",
|
||||
}, &i18n.Message{
|
||||
ID: "url_tag",
|
||||
Other: "url tag:",
|
||||
|
||||
@@ -10,8 +10,14 @@ var EImportsHead = map[string]string{
|
||||
|
||||
// TypeMysqlDicMp Accurate matching type.精确匹配类型
|
||||
var TypeMysqlDicMp = map[string]string{
|
||||
"tinyint": "int8",
|
||||
"tinyint unsigned": "uint8",
|
||||
"smallint": "int16",
|
||||
"smallint unsigned": "uint16",
|
||||
"int": "int",
|
||||
"int unsigned": "uint",
|
||||
"bigint": "int64",
|
||||
"bigint unsigned": "uint64",
|
||||
"varchar": "string",
|
||||
"char": "string",
|
||||
"date": "time.Time",
|
||||
@@ -33,7 +39,7 @@ var TypeMysqlDicMp = map[string]string{
|
||||
// TypeMysqlMatchMp Fuzzy Matching Types.模糊匹配类型
|
||||
var TypeMysqlMatchMp = map[string]string{
|
||||
`^(tinyint)[(]\d+[)]`: "int8",
|
||||
`^(smallint)[(]\d+[)]`: "int8",
|
||||
`^(smallint)[(]\d+[)]`: "int16",
|
||||
`^(int)[(]\d+[)]`: "int",
|
||||
`^(bigint)[(]\d+[)]`: "int64",
|
||||
`^(char)[(]\d+[)]`: "string",
|
||||
@@ -44,4 +50,5 @@ var TypeMysqlMatchMp = map[string]string{
|
||||
`^(mediumint)[(]\d+[)]`: "string",
|
||||
`^(double)[(]\d+,\d+[)]`: "float64",
|
||||
`^(float)[(]\d+,\d+[)]`: "float64",
|
||||
`^(datetime)[(]\d+[)]`: "time.Time",
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
package genfunc
|
||||
|
||||
const (
|
||||
genTnf = `
|
||||
// TableName get sql table name.获取数据库表名
|
||||
func (m *{{.StructName}}) TableName() string {
|
||||
return "{{.TableName}}"
|
||||
}
|
||||
`
|
||||
genBase = `
|
||||
package {{.PackageName}}
|
||||
import (
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package genfunc
|
||||
|
||||
// GetGenTableNameTemp get gen base template str
|
||||
func GetGenTableNameTemp() string {
|
||||
return genTnf
|
||||
}
|
||||
|
||||
// GetGenBaseTemp get gen base template str
|
||||
func GetGenBaseTemp() string {
|
||||
return genBase
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package genstruct
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/xxjwxc/gormt/data/config"
|
||||
"github.com/xxjwxc/gormt/data/view/cnf"
|
||||
"github.com/xxjwxc/gormt/data/view/generate"
|
||||
"github.com/xxjwxc/gormt/data/view/genfunc"
|
||||
)
|
||||
|
||||
// SetName Setting element name.设置元素名字
|
||||
@@ -96,6 +99,11 @@ func (s *GenStruct) SetCreatTableStr(sql string) {
|
||||
s.SQLBuildStr = sql
|
||||
}
|
||||
|
||||
// SetTableName Setting the name of struct.设置struct名字
|
||||
func (s *GenStruct) SetTableName(name string) {
|
||||
s.TableName = name
|
||||
}
|
||||
|
||||
// SetStructName Setting the name of struct.设置struct名字
|
||||
func (s *GenStruct) SetStructName(name string) {
|
||||
s.Name = name
|
||||
@@ -125,6 +133,21 @@ func (s *GenStruct) AddElement(e ...GenElement) {
|
||||
s.Em = append(s.Em, e...)
|
||||
}
|
||||
|
||||
func (s *GenStruct) GenerateTableName() []string {
|
||||
tmpl, err := template.New("gen_tnf").Parse(genfunc.GetGenTableNameTemp())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var data struct {
|
||||
TableName string
|
||||
StructName string
|
||||
}
|
||||
data.TableName, data.StructName = s.TableName, s.Name
|
||||
var buf bytes.Buffer
|
||||
tmpl.Execute(&buf, data)
|
||||
return []string{buf.String()}
|
||||
}
|
||||
|
||||
// Generates Get the result data.获取结果数据
|
||||
func (s *GenStruct) Generates() []string {
|
||||
var p generate.PrintAtom
|
||||
@@ -158,13 +181,9 @@ func (s *GenStruct) GeneratesColor() []string {
|
||||
}
|
||||
p.Add("\033[32;1m " + s.Notes + " \033[0m")
|
||||
p.Add("\033[34;1m type \033[0m", s.Name, "\033[34;1m struct \033[0m {")
|
||||
mp := make(map[string]bool, len(s.Em))
|
||||
for _, v := range s.Em {
|
||||
if !mp[v.Name] {
|
||||
mp[v.Name] = true
|
||||
p.Add(" \t\t" + v.GenerateColor())
|
||||
}
|
||||
}
|
||||
p.Add(" }")
|
||||
|
||||
return p.Generates()
|
||||
@@ -215,6 +234,16 @@ func (p *GenPackage) Generate() string {
|
||||
}
|
||||
// -----------end
|
||||
|
||||
// add table name func
|
||||
if config.GetIsTableName() {
|
||||
for _, v := range p.Structs {
|
||||
for _, v1 := range v.GenerateTableName() {
|
||||
pa.Add(v1)
|
||||
}
|
||||
}
|
||||
}
|
||||
// -----------end
|
||||
|
||||
// add func
|
||||
for _, v := range p.FuncStrList {
|
||||
pa.Add(v)
|
||||
|
||||
@@ -11,6 +11,7 @@ type GenElement struct {
|
||||
// GenStruct struct of IStruct .结构体
|
||||
type GenStruct struct {
|
||||
SQLBuildStr string // Create SQL statements.创建sql语句
|
||||
TableName string // table_name.表名
|
||||
Name string // name.名字
|
||||
Notes string // notes.注释
|
||||
Em []GenElement // em.元素组合
|
||||
|
||||
@@ -60,6 +60,18 @@ func (m *mysqlModel) GetPkgName() string {
|
||||
|
||||
func getPackageInfo(orm *mysqldb.MySqlDB, info *model.DBInfo) {
|
||||
tabls := getTables(orm) // get table and notes
|
||||
if m := config.GetTableList(); len(m) > 0 {
|
||||
// 制定了表之后
|
||||
newTabls := make(map[string]string)
|
||||
for t := range m {
|
||||
if notes, ok := tabls[t]; ok {
|
||||
newTabls[t] = notes
|
||||
} else {
|
||||
fmt.Printf("table: %s not found in db\n", t)
|
||||
}
|
||||
}
|
||||
tabls = newTabls
|
||||
}
|
||||
for tabName, notes := range tabls {
|
||||
var tab model.TabInfo
|
||||
tab.Name = tabName
|
||||
|
||||
@@ -29,7 +29,11 @@ func Generate(info DBInfo) (out []GenOutInfo, m _Model) {
|
||||
// struct
|
||||
var stt GenOutInfo
|
||||
stt.FileCtx = m.generate()
|
||||
if fn := config.GetOutFileName(); fn != "" {
|
||||
stt.FileName = fn
|
||||
} else {
|
||||
stt.FileName = info.DbName + ".go"
|
||||
}
|
||||
out = append(out, stt)
|
||||
// ------end
|
||||
|
||||
@@ -48,6 +52,7 @@ func (m *_Model) GetPackage() genstruct.GenPackage {
|
||||
pkg.SetPackage(m.info.PackageName) //package name
|
||||
for _, tab := range m.info.TabList {
|
||||
var sct genstruct.GenStruct
|
||||
sct.SetTableName(tab.Name)
|
||||
sct.SetStructName(getCamelName(tab.Name)) // Big hump.大驼峰
|
||||
sct.SetNotes(tab.Notes)
|
||||
sct.AddElement(m.genTableElement(tab.Em)...) // build element.构造元素
|
||||
|
||||
21
go.sum
21
go.sum
@@ -12,8 +12,6 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
|
||||
github.com/ant0ine/go-json-rest v3.3.2+incompatible/go.mod h1:q6aCt0GfU6LhpBsnZ/2U+mwe+0XB5WStbmwyoPfc+sk=
|
||||
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
|
||||
github.com/atotto/clipboard v0.1.2 h1:YZCtFu5Ie8qX2VmVTBnrqLSiU9XOWwqNRmdT3gIQzbY=
|
||||
github.com/atotto/clipboard v0.1.2/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
|
||||
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ=
|
||||
github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394/go.mod h1:Q8n74mJTIgjX4RBBcHnJ05h//6/k6foqmgE45jTQtxg=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
@@ -25,7 +23,6 @@ github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8Nz
|
||||
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/denisenkom/go-mssqldb v0.0.0-20190515213511-eb9f6a1743f3 h1:tkum0XDgfR0jcVVXuTsYv/erY2NnEDqwRojbxR1rBYA=
|
||||
github.com/denisenkom/go-mssqldb v0.0.0-20190515213511-eb9f6a1743f3/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM=
|
||||
@@ -36,6 +33,8 @@ github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DP
|
||||
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
|
||||
github.com/ezbuy/tgen v0.0.0-20180109020500-95ef13895032/go.mod h1:OeW1N0acAlRaGTlOG8jRZZUKEtyiGa0qvD+lWNWb9vs=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fzipp/gocyclo v0.0.0-20150627053110-6acd4345c835 h1:roDmqJ4Qes7hrDOsWsMCce0vQHz3xiMPjJ9m4c2eeNs=
|
||||
github.com/fzipp/gocyclo v0.0.0-20150627053110-6acd4345c835/go.mod h1:BjL/N0+C+j9uNX+1xcNuM9vdSIcXCZrQZUYbXOFbgN8=
|
||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
|
||||
@@ -53,7 +52,6 @@ github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
@@ -82,10 +80,8 @@ github.com/kardianos/service v1.0.1-0.20191017145738-4df36c9fc1c6/go.mod h1:8CzD
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
|
||||
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
|
||||
@@ -101,6 +97,7 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/nicksnyder/go-i18n v2.0.3+incompatible h1:XCCaWsCoy4KlWkhOr+63dkv6oJmitJ573uJqDBAiFiQ=
|
||||
github.com/nicksnyder/go-i18n/v2 v2.0.3 h1:ks/JkQiOEhhuF6jpNvx+Wih1NIiXzUnZeZVnJuI8R8M=
|
||||
github.com/nicksnyder/go-i18n/v2 v2.0.3/go.mod h1:oDab7q8XCYMRlcrBnaY/7B1eOectbvj6B1UPBT+p5jo=
|
||||
github.com/nsf/termbox-go v0.0.0-20191229070316-58d4fcbce2a7 h1:OkWEy7aQeQTbgdrcGi9bifx+Y6bMM7ae7y42hDFaBvA=
|
||||
@@ -114,7 +111,6 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9
|
||||
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
|
||||
@@ -138,20 +134,21 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
|
||||
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
|
||||
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
|
||||
github.com/xxjwxc/public v0.0.0-20200221114751-56810b3fcc29 h1:C0fnjiwnCBjovovCTkrjVXQtqd+UdVD2N8yaVK8LHwk=
|
||||
github.com/xxjwxc/public v0.0.0-20200221114751-56810b3fcc29/go.mod h1:lhh94GsxhTweM/OaF7eFzOAgVV6fSSbBvA6zOtOVmdU=
|
||||
github.com/xxjwxc/public v0.0.0-20191107073037-ea6b812d567f h1:PyaqoUhjkgpBGR/8LXWvk3yzrILMXC7Ygu8xhl5+sM8=
|
||||
github.com/xxjwxc/public v0.0.0-20191107073037-ea6b812d567f/go.mod h1:j0CCXMUDtykGMfOoBpy1pfmzEeBk2JVusosjbgjfMZg=
|
||||
github.com/xxjwxc/public v0.0.0-20200120133922-c61314a90a4a h1:sQ+O2UwDj1ShdZ6NLgp98cmaZLWrkFpVJB+wOzj1kDQ=
|
||||
github.com/xxjwxc/public v0.0.0-20200120133922-c61314a90a4a/go.mod h1:UYQUNNJmUzNKpjY5ctz1n/XoJonmhAIgD51zS2rEsek=
|
||||
github.com/xxjwxc/public v0.0.0-20200120153226-f36cf754df21 h1:1OF0Q6FGQhmziN4yvHLiF9XXOqfChL5z4rcogSQqCos=
|
||||
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c h1:Vj5n4GlwjmQteupaxJ9+0FNOmBrHfq7vN4btdGoDZgI=
|
||||
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284 h1:rlLehGeYg6jfoyz/eDqDU1iRXLKfR42nnNh57ytKEWo=
|
||||
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
@@ -198,7 +195,6 @@ golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3
|
||||
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
@@ -207,7 +203,6 @@ google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/eapache/queue.v1 v1.1.0/go.mod h1:wNtmx1/O7kZSR9zNT1TTOJ7GLpm3Vn7srzlfylFbQwU=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
|
||||
Reference in New Issue
Block a user