@@ -3,15 +3,17 @@ base:
|
||||
out_dir : ./model # 输出目录
|
||||
url_tag : json # web url tag(json,db(https://github.com/google/go-querystring))
|
||||
language : # 语言(English,中 文)
|
||||
db_tag : gorm # 数据库标签(gorm,db)
|
||||
simple : false # 简单输出(默认gorm标签不输出)
|
||||
db_tag : gorm # 数据库标签名(gorm,db)
|
||||
simple : true # 简单输出(默认只输出gorm主键和字段标签)
|
||||
is_db_tag : true # 是否输出 数据库标签(gorm,db)
|
||||
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 : true # 是否直接生成表名,列名
|
||||
is_table_name : true # 是否直接生成表名
|
||||
is_column_name : true # 是否直接生成列名
|
||||
is_null_to_point : false # 数据库默认 'DEFAULT NULL' 时设置结构为指针类型
|
||||
table_prefix : "" # 表前缀, 如果有则使用, 没有留空
|
||||
table_names: "" # 指定表生成,多个表用,隔开
|
||||
|
||||
@@ -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