add config with is_db_tag
This commit is contained in:
@@ -16,6 +16,7 @@ type Config struct {
|
||||
Language string `yaml:"language"` // language
|
||||
DbTag string `yaml:"db_tag"` // 数据库标签(gormt,db)
|
||||
Simple bool `yaml:"simple"`
|
||||
IsDbTag bool `yaml:"is_db_tag"` // 是否输出 数据库标签
|
||||
IsWEBTag bool `yaml:"is_web_tag"`
|
||||
IsWebTagPkHidden bool `yaml:"is_web_tag_pk_hidden"` // web标记是否隐藏主键
|
||||
IsForeignKey bool `yaml:"is_foreign_key"`
|
||||
@@ -98,6 +99,16 @@ func SetSimple(b bool) {
|
||||
_map.Simple = b
|
||||
}
|
||||
|
||||
// GetIsDbTag is_db_tag
|
||||
func GetIsDbTag() bool {
|
||||
return _map.IsDbTag
|
||||
}
|
||||
|
||||
// SetIsDbTag is_db_tag
|
||||
func SetIsDbTag(b bool) {
|
||||
_map.IsDbTag = b
|
||||
}
|
||||
|
||||
// GetIsWEBTag json tag.json标记
|
||||
func GetIsWEBTag() bool {
|
||||
return _map.IsWEBTag
|
||||
|
||||
@@ -292,11 +292,13 @@ func buttonSave(g *gocui.Gui, v *gocui.View) error {
|
||||
|
||||
config.SetIsDev(getBool(mp["is_dev"]))
|
||||
config.SetSimple(getBool(mp["is_simple"]))
|
||||
config.SetIsDbTag(getBool(mp["is_db_tag"]))
|
||||
config.SetIsOutSQL(getBool(mp["is_out_sql"]))
|
||||
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.SetIsColumnName(getBool(mp["is_column_name"]))
|
||||
config.SetURLTag(mp["url_tag"])
|
||||
config.SetDBTag(mp["db_tag"])
|
||||
config.SetLG(mp["language"])
|
||||
|
||||
@@ -123,44 +123,61 @@ func (m *_Model) genTableElement(cols []ColumnsInfo) (el []genstruct.GenElement)
|
||||
tmp.SetName(getCamelName(v.Name))
|
||||
tmp.SetNotes(v.Notes)
|
||||
tmp.SetType(getTypeName(v.Type, v.IsNull))
|
||||
// not simple output. 默认不输出gorm标签
|
||||
if !config.GetSimple() {
|
||||
for _, v1 := range v.Index {
|
||||
switch v1.Key {
|
||||
// case ColumnsKeyDefault:
|
||||
case ColumnsKeyPrimary: // primary key.主键
|
||||
tmp.AddTag(_tagGorm, "primaryKey")
|
||||
isPK = true
|
||||
case ColumnsKeyUnique: // unique key.唯一索引
|
||||
tmp.AddTag(_tagGorm, "unique")
|
||||
case ColumnsKeyIndex: // index key.复合索引
|
||||
uninStr := getUninStr("index", ":", v1.KeyName)
|
||||
// 兼容 gorm 本身 sort 标签
|
||||
if v1.KeyName == "sort" {
|
||||
uninStr = "index"
|
||||
// is_db_tag. 是否输出gorm标签
|
||||
if config.GetIsDbTag() {
|
||||
// not simple output. 默认只输出gorm主键和字段标签
|
||||
if !config.GetSimple() {
|
||||
for _, v1 := range v.Index {
|
||||
switch v1.Key {
|
||||
// case ColumnsKeyDefault:
|
||||
case ColumnsKeyPrimary: // primary key.主键
|
||||
tmp.AddTag(_tagGorm, "primaryKey")
|
||||
isPK = true
|
||||
case ColumnsKeyUnique: // unique key.唯一索引
|
||||
tmp.AddTag(_tagGorm, "unique")
|
||||
case ColumnsKeyIndex: // index key.复合索引
|
||||
uninStr := getUninStr("index", ":", v1.KeyName)
|
||||
// 兼容 gorm 本身 sort 标签
|
||||
if v1.KeyName == "sort" {
|
||||
uninStr = "index"
|
||||
}
|
||||
if v1.KeyType == "FULLTEXT" {
|
||||
uninStr += ",class:FULLTEXT"
|
||||
}
|
||||
tmp.AddTag(_tagGorm, uninStr)
|
||||
case ColumnsKeyUniqueIndex: // unique index key.唯一复合索引
|
||||
tmp.AddTag(_tagGorm, getUninStr("uniqueIndex", ":", v1.KeyName))
|
||||
}
|
||||
if v1.KeyType == "FULLTEXT" {
|
||||
uninStr += ",class:FULLTEXT"
|
||||
}
|
||||
} else {
|
||||
for _, v1 := range v.Index {
|
||||
switch v1.Key {
|
||||
// case ColumnsKeyDefault:
|
||||
case ColumnsKeyPrimary: // primary key.主键
|
||||
tmp.AddTag(_tagGorm, "primaryKey")
|
||||
isPK = true
|
||||
}
|
||||
tmp.AddTag(_tagGorm, uninStr)
|
||||
case ColumnsKeyUniqueIndex: // unique index key.唯一复合索引
|
||||
tmp.AddTag(_tagGorm, getUninStr("uniqueIndex", ":", v1.KeyName))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(v.Name) > 0 {
|
||||
// not simple output
|
||||
if !config.GetSimple() {
|
||||
tmp.AddTag(_tagGorm, "column:"+v.Name)
|
||||
tmp.AddTag(_tagGorm, "type:"+v.Type)
|
||||
if !v.IsNull {
|
||||
tmp.AddTag(_tagGorm, "not null")
|
||||
}
|
||||
// default tag
|
||||
if len(v.Gormt) > 0 {
|
||||
tmp.AddTag(_tagGorm, v.Gormt)
|
||||
// is_db_tag. 是否输出gorm标签
|
||||
if config.GetIsDbTag() {
|
||||
// not simple output
|
||||
if !config.GetSimple() {
|
||||
tmp.AddTag(_tagGorm, "column:"+v.Name)
|
||||
tmp.AddTag(_tagGorm, "type:"+v.Type)
|
||||
if !v.IsNull {
|
||||
tmp.AddTag(_tagGorm, "not null")
|
||||
}
|
||||
// default tag
|
||||
if len(v.Gormt) > 0 {
|
||||
tmp.AddTag(_tagGorm, v.Gormt)
|
||||
}
|
||||
} else {
|
||||
tmp.AddTag(_tagGorm, "column:"+v.Name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user