This commit is contained in:
xxjwxc
2020-02-29 00:19:25 +08:00
parent 73c399165e
commit ce3904575d
11 changed files with 132 additions and 80 deletions

View File

@@ -10,8 +10,6 @@ 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",
@@ -24,6 +22,7 @@ var TypeMysqlDicMp = map[string]string{
"datetime": "time.Time",
"bit(1)": "int8",
"tinyint": "int8",
"tinyint unsigned": "uint8",
"tinyint(1)": "int8",
"tinyint(1) unsigned": "int8",
"json": "string",

View File

@@ -181,8 +181,12 @@ 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 {
p.Add(" \t\t" + v.GenerateColor())
if !mp[v.Name] {
mp[v.Name] = true
p.Add(" \t\t" + v.GenerateColor())
}
}
p.Add(" }")
@@ -231,12 +235,8 @@ func (p *GenPackage) Generate() string {
for _, v1 := range v.Generates() {
pa.Add(v1)
}
}
// -----------end
// add table name func
if config.GetIsTableName() {
for _, v := range p.Structs {
if config.GetIsTableName() { // add table name func
for _, v1 := range v.GenerateTableName() {
pa.Add(v1)
}

View File

@@ -60,18 +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
}
// 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

View File

@@ -29,11 +29,8 @@ 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"
}
stt.FileName = info.DbName + ".go"
out = append(out, stt)
// ------end