From 3dea08f1e40f0e6db6a4a393551e94d5beb1d0ec Mon Sep 17 00:00:00 2001 From: xxj <346944475@qq.com> Date: Wed, 6 Jul 2022 18:41:33 +0800 Subject: [PATCH] add autoIncrement --- data/view/model/def.go | 3 ++- data/view/model/genmysql/def.go | 1 + data/view/model/genmysql/genmysql.go | 1 + data/view/model/model.go | 3 +++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/data/view/model/def.go b/data/view/model/def.go index f017c0d..8d4a268 100644 --- a/data/view/model/def.go +++ b/data/view/model/def.go @@ -39,6 +39,7 @@ type TabInfo struct { type ColumnsInfo struct { BaseInfo IsNull bool // null if db is set null + Extra string // Extra (AUTO_INCREMENT 自增加) Type string // Type.类型标记 Gormt string // 默认值 Index []KList // index list.index列表 @@ -117,7 +118,7 @@ type funDef struct { Em []EmInfo // index 列表 Primary []FList // primary unique Index []FList // index - IsOutPage bool // 是否开启分页 + IsOutPage bool // 是否开启分页 } // diff --git a/data/view/model/genmysql/def.go b/data/view/model/genmysql/def.go index 570ebd1..4050912 100644 --- a/data/view/model/genmysql/def.go +++ b/data/view/model/genmysql/def.go @@ -16,6 +16,7 @@ type genColumns struct { Key string `gorm:"column:Key"` Desc string `gorm:"column:Comment"` Null string `gorm:"column:Null"` + Extra string `gorm:"Extra"` Default *string `gorm:"column:Default"` } diff --git a/data/view/model/genmysql/genmysql.go b/data/view/model/genmysql/genmysql.go index 32141ad..33bae6a 100644 --- a/data/view/model/genmysql/genmysql.go +++ b/data/view/model/genmysql/genmysql.go @@ -153,6 +153,7 @@ func (m *mysqlModel) getTableElement(orm *mysqldb.MySqlDB, tab string) (el []mod var tmp model.ColumnsInfo tmp.Name = v.Field tmp.Type = v.Type + tmp.Extra = v.Extra FixNotes(&tmp, v.Desc) // 分析表注释 if v.Default != nil { diff --git a/data/view/model/model.go b/data/view/model/model.go index 7a23c54..7e5d11c 100755 --- a/data/view/model/model.go +++ b/data/view/model/model.go @@ -140,6 +140,9 @@ func (m *_Model) genTableElement(cols []ColumnsInfo) (el []genstruct.GenElement) if len(_tagGorm) > 0 { // not simple output. 默认只输出gorm主键和字段标签 if !config.GetSimple() { + if strings.EqualFold(v.Extra, "auto_increment") { + tmp.AddTag(_tagGorm, "autoIncrement:true") + } for _, v1 := range v.Index { switch v1.Key { // case ColumnsKeyDefault: