@@ -9,6 +9,7 @@ simple : false # 简单输出(默认gorm标签不输出)
|
|||||||
is_out_sql : false # 是否输出 sql 原信息
|
is_out_sql : false # 是否输出 sql 原信息
|
||||||
is_out_func : true # 是否输出 快捷函数
|
is_out_func : true # 是否输出 快捷函数
|
||||||
is_web_tag : true # 是否打web标记(json标记前提条件)
|
is_web_tag : true # 是否打web标记(json标记前提条件)
|
||||||
|
is_web_tag_pk_hidden: true # web标记是否隐藏主键
|
||||||
is_foreign_key : true # 是否导出外键关联
|
is_foreign_key : true # 是否导出外键关联
|
||||||
is_gui : false # 是否ui模式显示
|
is_gui : false # 是否ui模式显示
|
||||||
is_table_name : false # 是否直接生成表名函数
|
is_table_name : false # 是否直接生成表名函数
|
||||||
|
|||||||
@@ -8,21 +8,22 @@ import (
|
|||||||
|
|
||||||
// Config custom config struct
|
// Config custom config struct
|
||||||
type Config struct {
|
type Config struct {
|
||||||
CfgBase `yaml:"base"`
|
CfgBase `yaml:"base"`
|
||||||
MySQLInfo MysqlDbInfo `yaml:"mysql_info"`
|
MySQLInfo MysqlDbInfo `yaml:"mysql_info"`
|
||||||
OutDir string `yaml:"out_dir"`
|
OutDir string `yaml:"out_dir"`
|
||||||
URLTag string `yaml:"url_tag"` // url tag
|
URLTag string `yaml:"url_tag"` // url tag
|
||||||
Language string `yaml:"language"` // language
|
Language string `yaml:"language"` // language
|
||||||
DbTag string `yaml:"db_tag"` // 数据库标签(gormt,db)
|
DbTag string `yaml:"db_tag"` // 数据库标签(gormt,db)
|
||||||
Simple bool `yaml:"simple"`
|
Simple bool `yaml:"simple"`
|
||||||
IsWEBTag bool `yaml:"is_web_tag"`
|
IsWEBTag bool `yaml:"is_web_tag"`
|
||||||
SingularTable bool `yaml:"singular_table"`
|
IsWebTagPkHidden bool `yaml:"is_web_tag_pk_hidden"` // web标记是否隐藏主键
|
||||||
IsForeignKey bool `yaml:"is_foreign_key"`
|
SingularTable bool `yaml:"singular_table"`
|
||||||
IsOutSQL bool `yaml:"is_out_sql"`
|
IsForeignKey bool `yaml:"is_foreign_key"`
|
||||||
IsOutFunc bool `yaml:"is_out_func"`
|
IsOutSQL bool `yaml:"is_out_sql"`
|
||||||
IsGUI bool `yaml:"is_gui"` //
|
IsOutFunc bool `yaml:"is_out_func"`
|
||||||
IsTableName bool `yaml:"is_table_name"`
|
IsGUI bool `yaml:"is_gui"` //
|
||||||
OutFileName string `yaml:"-"`
|
IsTableName bool `yaml:"is_table_name"`
|
||||||
|
OutFileName string `yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MysqlDbInfo mysql database information. mysql 数据库信息
|
// MysqlDbInfo mysql database information. mysql 数据库信息
|
||||||
@@ -94,6 +95,11 @@ func GetIsWEBTag() bool {
|
|||||||
return _map.IsWEBTag
|
return _map.IsWEBTag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetIsWebTagPkHidden web tag是否隐藏主键
|
||||||
|
func GetIsWebTagPkHidden() bool {
|
||||||
|
return _map.IsWebTagPkHidden
|
||||||
|
}
|
||||||
|
|
||||||
// GetIsForeignKey if is foreign key
|
// GetIsForeignKey if is foreign key
|
||||||
func GetIsForeignKey() bool {
|
func GetIsForeignKey() bool {
|
||||||
return _map.IsForeignKey
|
return _map.IsForeignKey
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ func (m *_Model) genTableElement(cols []ColumnsInfo) (el []genstruct.GenElement)
|
|||||||
|
|
||||||
for _, v := range cols {
|
for _, v := range cols {
|
||||||
var tmp genstruct.GenElement
|
var tmp genstruct.GenElement
|
||||||
|
var isPK bool
|
||||||
if strings.EqualFold(v.Type, "gorm.Model") { // gorm model
|
if strings.EqualFold(v.Type, "gorm.Model") { // gorm model
|
||||||
tmp.SetType(v.Type) //
|
tmp.SetType(v.Type) //
|
||||||
} else {
|
} else {
|
||||||
@@ -86,6 +87,7 @@ func (m *_Model) genTableElement(cols []ColumnsInfo) (el []genstruct.GenElement)
|
|||||||
// case ColumnsKeyDefault:
|
// case ColumnsKeyDefault:
|
||||||
case ColumnsKeyPrimary: // primary key.主键
|
case ColumnsKeyPrimary: // primary key.主键
|
||||||
tmp.AddTag(_tagGorm, "primary_key")
|
tmp.AddTag(_tagGorm, "primary_key")
|
||||||
|
isPK = true
|
||||||
case ColumnsKeyUnique: // unique key.唯一索引
|
case ColumnsKeyUnique: // unique key.唯一索引
|
||||||
tmp.AddTag(_tagGorm, "unique")
|
tmp.AddTag(_tagGorm, "unique")
|
||||||
case ColumnsKeyIndex: // index key.复合索引
|
case ColumnsKeyIndex: // index key.复合索引
|
||||||
@@ -108,7 +110,7 @@ func (m *_Model) genTableElement(cols []ColumnsInfo) (el []genstruct.GenElement)
|
|||||||
|
|
||||||
// json tag
|
// json tag
|
||||||
if config.GetIsWEBTag() {
|
if config.GetIsWEBTag() {
|
||||||
if strings.EqualFold(v.Name, "id") {
|
if isPK && config.GetIsWebTagPkHidden() {
|
||||||
tmp.AddTag(_tagJSON, "-")
|
tmp.AddTag(_tagJSON, "-")
|
||||||
} else {
|
} else {
|
||||||
tmp.AddTag(_tagJSON, mybigcamel.UnMarshal(v.Name))
|
tmp.AddTag(_tagJSON, mybigcamel.UnMarshal(v.Name))
|
||||||
|
|||||||
Reference in New Issue
Block a user