Merge branch 'xxjwxc:master' into master
This commit is contained in:
@@ -3,15 +3,17 @@ base:
|
|||||||
out_dir : ./model # 输出目录
|
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)
|
||||||
simple : false # 简单输出(默认gorm标签不输出)
|
simple : true # 简单输出(默认只输出gorm主键和字段标签)
|
||||||
|
is_db_tag : true # 是否输出 数据库标签(gorm,db)
|
||||||
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_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 : true # 是否直接生成表名,列名
|
is_table_name : true # 是否直接生成表名
|
||||||
|
is_column_name : true # 是否直接生成列名
|
||||||
is_null_to_point : false # 数据库默认 'DEFAULT NULL' 时设置结构为指针类型
|
is_null_to_point : false # 数据库默认 'DEFAULT NULL' 时设置结构为指针类型
|
||||||
table_prefix : "" # 表前缀, 如果有则使用, 没有留空
|
table_prefix : "" # 表前缀, 如果有则使用, 没有留空
|
||||||
table_names: "" # 指定表生成,多个表用,隔开
|
table_names: "" # 指定表生成,多个表用,隔开
|
||||||
|
|||||||
@@ -310,8 +310,3 @@ func SetIsColumnName(isColumnName bool) {
|
|||||||
func GetIsOutFileByTableName() bool {
|
func GetIsOutFileByTableName() bool {
|
||||||
return _map.IsOutFileByTableName
|
return _map.IsOutFileByTableName
|
||||||
}
|
}
|
||||||
|
|
||||||
//SetIsOutFileByTableName set gen ColumnName config. 设置是否根据表名生成文件
|
|
||||||
func SetIsOutFileByTableName(isOutFileByTableName bool) {
|
|
||||||
_map.IsColumnName = isOutFileByTableName
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -297,6 +297,7 @@ func buttonSave(g *gocui.Gui, v *gocui.View) error {
|
|||||||
config.SetForeignKey(getBool(mp["is_foreign_key"]))
|
config.SetForeignKey(getBool(mp["is_foreign_key"]))
|
||||||
config.SetIsGUI(getBool(mp["is_gui"]))
|
config.SetIsGUI(getBool(mp["is_gui"]))
|
||||||
config.SetIsTableName(getBool(mp["is_table_name"]))
|
config.SetIsTableName(getBool(mp["is_table_name"]))
|
||||||
|
config.SetIsColumnName(getBool(mp["is_column_name"]))
|
||||||
config.SetURLTag(mp["url_tag"])
|
config.SetURLTag(mp["url_tag"])
|
||||||
config.SetDBTag(mp["db_tag"])
|
config.SetDBTag(mp["db_tag"])
|
||||||
config.SetLG(mp["language"])
|
config.SetLG(mp["language"])
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type _BaseMgr struct {
|
|||||||
isRelated bool
|
isRelated bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCtx set context
|
// SetTimeOut set timeout
|
||||||
func (obj *_BaseMgr) SetTimeOut(timeout time.Duration) {
|
func (obj *_BaseMgr) SetTimeOut(timeout time.Duration) {
|
||||||
obj.ctx, obj.cancel = context.WithTimeout(context.Background(), timeout)
|
obj.ctx, obj.cancel = context.WithTimeout(context.Background(), timeout)
|
||||||
obj.timeout = timeout
|
obj.timeout = timeout
|
||||||
@@ -49,7 +49,7 @@ func (obj *_BaseMgr) SetCtx(c context.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ctx get context
|
// GetCtx get context
|
||||||
func (obj *_BaseMgr) GetCtx() context.Context {
|
func (obj *_BaseMgr) GetCtx() context.Context {
|
||||||
return obj.ctx
|
return obj.ctx
|
||||||
}
|
}
|
||||||
@@ -204,6 +204,13 @@ func (obj *_{{$obj.StructName}}Mgr) Gets() (results []*{{$obj.StructName}}, err
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////// gorm replace /////////////////////////////////
|
||||||
|
func (obj *_{{$obj.StructName}}Mgr) Count(count *int64) (tx *gorm.DB) {
|
||||||
|
return obj.DB.WithContext(obj.ctx).Model({{$obj.StructName}}{}).Count(count)
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//////////////////////////option case ////////////////////////////////////////////
|
//////////////////////////option case ////////////////////////////////////////////
|
||||||
{{range $oem := $obj.Em}}
|
{{range $oem := $obj.Em}}
|
||||||
// With{{$oem.ColStructName}} {{$oem.ColName}}获取 {{$oem.Notes}}
|
// With{{$oem.ColStructName}} {{$oem.ColName}}获取 {{$oem.Notes}}
|
||||||
|
|||||||
@@ -123,44 +123,61 @@ func (m *_Model) genTableElement(cols []ColumnsInfo) (el []genstruct.GenElement)
|
|||||||
tmp.SetName(getCamelName(v.Name))
|
tmp.SetName(getCamelName(v.Name))
|
||||||
tmp.SetNotes(v.Notes)
|
tmp.SetNotes(v.Notes)
|
||||||
tmp.SetType(getTypeName(v.Type, v.IsNull))
|
tmp.SetType(getTypeName(v.Type, v.IsNull))
|
||||||
// not simple output. 默认不输出gorm标签
|
// 是否输出gorm标签
|
||||||
if !config.GetSimple() {
|
if len(_tagGorm) > 0 {
|
||||||
for _, v1 := range v.Index {
|
// not simple output. 默认只输出gorm主键和字段标签
|
||||||
switch v1.Key {
|
if !config.GetSimple() {
|
||||||
// case ColumnsKeyDefault:
|
for _, v1 := range v.Index {
|
||||||
case ColumnsKeyPrimary: // primary key.主键
|
switch v1.Key {
|
||||||
tmp.AddTag(_tagGorm, "primaryKey")
|
// case ColumnsKeyDefault:
|
||||||
isPK = true
|
case ColumnsKeyPrimary: // primary key.主键
|
||||||
case ColumnsKeyUnique: // unique key.唯一索引
|
tmp.AddTag(_tagGorm, "primaryKey")
|
||||||
tmp.AddTag(_tagGorm, "unique")
|
isPK = true
|
||||||
case ColumnsKeyIndex: // index key.复合索引
|
case ColumnsKeyUnique: // unique key.唯一索引
|
||||||
uninStr := getUninStr("index", ":", v1.KeyName)
|
tmp.AddTag(_tagGorm, "unique")
|
||||||
// 兼容 gorm 本身 sort 标签
|
case ColumnsKeyIndex: // index key.复合索引
|
||||||
if v1.KeyName == "sort" {
|
uninStr := getUninStr("index", ":", v1.KeyName)
|
||||||
uninStr = "index"
|
// 兼容 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 {
|
if len(v.Name) > 0 {
|
||||||
// not simple output
|
// 是否输出gorm标签
|
||||||
if !config.GetSimple() {
|
if len(_tagGorm) > 0 {
|
||||||
tmp.AddTag(_tagGorm, "column:"+v.Name)
|
// not simple output
|
||||||
tmp.AddTag(_tagGorm, "type:"+v.Type)
|
if !config.GetSimple() {
|
||||||
if !v.IsNull {
|
tmp.AddTag(_tagGorm, "column:"+v.Name)
|
||||||
tmp.AddTag(_tagGorm, "not null")
|
tmp.AddTag(_tagGorm, "type:"+v.Type)
|
||||||
}
|
if !v.IsNull {
|
||||||
// default tag
|
tmp.AddTag(_tagGorm, "not null")
|
||||||
if len(v.Gormt) > 0 {
|
}
|
||||||
tmp.AddTag(_tagGorm, v.Gormt)
|
// 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