fix SingularTable
This commit is contained in:
@@ -4,7 +4,7 @@ out_dir : ./model # 输出目录
|
|||||||
url_tag : json # web url tag(json,db(https://github.com/google/go-querystring))
|
url_tag : json # web url tag(json,db(https://github.com/google/go-querystring))
|
||||||
language : # 语言(English,中 文)
|
language : # 语言(English,中 文)
|
||||||
db_tag : gorm # 数据库标签(gorm,db)
|
db_tag : gorm # 数据库标签(gorm,db)
|
||||||
singular_table : false # 单表模式:true:禁用表名复数,false:采用表明复数 参考:gorm.SingularTable
|
singular_table : true # 单表模式:true:禁用表名复数,false:采用表明复数 参考:gorm.SingularTable
|
||||||
simple : false # 简单输出(默认gorm标签不输出)
|
simple : false # 简单输出(默认gorm标签不输出)
|
||||||
is_out_sql : false # 是否输出 sql 原信息
|
is_out_sql : false # 是否输出 sql 原信息
|
||||||
is_out_func : true # 是否输出 快捷函数
|
is_out_func : true # 是否输出 快捷函数
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().StringVarP(&outDir, "outdir", "o", "", "输出目录")
|
rootCmd.PersistentFlags().StringVarP(&outDir, "outdir", "o", "", "输出目录")
|
||||||
rootCmd.MarkFlagRequired("outdir")
|
rootCmd.MarkFlagRequired("outdir")
|
||||||
|
|
||||||
rootCmd.PersistentFlags().BoolVarP(&singularTable, "singular", "s", false, "是否禁用表名复数")
|
rootCmd.PersistentFlags().BoolVarP(&singularTable, "singular", "s", true, "是否禁用表名复数")
|
||||||
rootCmd.MarkFlagRequired("singular")
|
rootCmd.MarkFlagRequired("singular")
|
||||||
|
|
||||||
rootCmd.PersistentFlags().BoolVarP(&foreignKey, "foreign", "f", false, "是否导出外键关联")
|
rootCmd.PersistentFlags().BoolVarP(&foreignKey, "foreign", "f", false, "是否导出外键关联")
|
||||||
|
|||||||
@@ -135,9 +135,13 @@ func (s *GenStruct) Generates() []string {
|
|||||||
}
|
}
|
||||||
p.Add(s.Notes)
|
p.Add(s.Notes)
|
||||||
p.Add("type", s.Name, "struct {")
|
p.Add("type", s.Name, "struct {")
|
||||||
|
mp := make(map[string]bool, len(s.Em))
|
||||||
for _, v := range s.Em {
|
for _, v := range s.Em {
|
||||||
|
if !mp[v.Name] {
|
||||||
|
mp[v.Name] = true
|
||||||
p.Add(v.Generate())
|
p.Add(v.Generate())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
p.Add("}")
|
p.Add("}")
|
||||||
|
|
||||||
return p.Generates()
|
return p.Generates()
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import (
|
|||||||
|
|
||||||
// getCamelName Big Hump or Capital Letter.大驼峰或者首字母大写
|
// getCamelName Big Hump or Capital Letter.大驼峰或者首字母大写
|
||||||
func getCamelName(name string) string {
|
func getCamelName(name string) string {
|
||||||
if config.GetSingularTable() { // If the table name plural is globally disabled.如果全局禁用表名复数
|
if !config.GetSingularTable() { // If the table name plural is globally disabled.如果全局禁用表名复数
|
||||||
return titleCase(name)
|
return mybigcamel.Marshal(strings.TrimSuffix(name, "s"))
|
||||||
}
|
}
|
||||||
|
|
||||||
return mybigcamel.Marshal(name)
|
return mybigcamel.Marshal(name)
|
||||||
|
|||||||
Reference in New Issue
Block a user