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