From acd9861d7fe15410657b9ae04755451abd8b5915 Mon Sep 17 00:00:00 2001 From: young Date: Wed, 23 Dec 2020 15:48:17 +0800 Subject: [PATCH] add: INDEX FULLTEXT add: Default value --- data/view/model/def.go | 1 + data/view/model/genmysql/def.go | 12 +++++++----- data/view/model/genmysql/genmysql.go | 12 ++++++++++++ data/view/model/model.go | 6 +++++- data/view/model/model_test.go | 2 -- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/data/view/model/def.go b/data/view/model/def.go index eacb5d8..c92f505 100644 --- a/data/view/model/def.go +++ b/data/view/model/def.go @@ -56,6 +56,7 @@ type KList struct { Key ColumnsKey // non_unique of (show keys from [table]) Multi bool // Multiple .是否多个(复合组建) KeyName string // key_name of (show keys from [table]) + KeyType string // Key_type of (show keys from [Index_type]) } // BaseInfo base common attribute. 基础属性 diff --git a/data/view/model/genmysql/def.go b/data/view/model/genmysql/def.go index a5e5c47..9eaf6df 100644 --- a/data/view/model/genmysql/def.go +++ b/data/view/model/genmysql/def.go @@ -6,15 +6,17 @@ type keys struct { NonUnique int `gorm:"column:Non_unique"` KeyName string `gorm:"column:Key_name"` ColumnName string `gorm:"column:Column_name"` + IndexType string `gorm:"column:Index_type"` } // genColumns show full columns type genColumns struct { - Field string `gorm:"column:Field"` - Type string `gorm:"column:Type"` - Key string `gorm:"column:Key"` - Desc string `gorm:"column:Comment"` - Null string `gorm:"column:Null"` + Field string `gorm:"column:Field"` + Type string `gorm:"column:Type"` + Key string `gorm:"column:Key"` + Desc string `gorm:"column:Comment"` + Null string `gorm:"column:Null"` + Default *string `gorm:"column:Default"` } //select table_schema,table_name,column_name,referenced_table_schema,referenced_table_name,referenced_column_name from INFORMATION_SCHEMA.KEY_COLUMN_USAGE diff --git a/data/view/model/genmysql/genmysql.go b/data/view/model/genmysql/genmysql.go index 5e8fb22..cc44f2d 100644 --- a/data/view/model/genmysql/genmysql.go +++ b/data/view/model/genmysql/genmysql.go @@ -144,6 +144,14 @@ func (m *mysqlModel) getTableElement(orm *mysqldb.MySqlDB, tab string) (el []mod tmp.Type = v.Type FixElementTag(&tmp, v.Desc) // 分析表注释 + if v.Default != nil { + if *v.Default == "" { + tmp.Gormt = "default:''" + } else { + tmp.Gormt = fmt.Sprintf("default:%s", *v.Default) + } + } + // keys if keylist, ok := KeyColumnMp[v.Field]; ok { // maybe have index or key for _, v := range keylist { @@ -152,6 +160,7 @@ func (m *mysqlModel) getTableElement(orm *mysqldb.MySqlDB, tab string) (el []mod tmp.Index = append(tmp.Index, model.KList{ Key: model.ColumnsKeyPrimary, Multi: (keyNameCount[v.KeyName] > 1), + KeyType: v.IndexType, }) } else { // unique if keyNameCount[v.KeyName] > 1 { @@ -159,12 +168,14 @@ func (m *mysqlModel) getTableElement(orm *mysqldb.MySqlDB, tab string) (el []mod Key: model.ColumnsKeyUniqueIndex, Multi: (keyNameCount[v.KeyName] > 1), KeyName: v.KeyName, + KeyType: v.IndexType, }) } else { // unique index key.唯一复合索引 tmp.Index = append(tmp.Index, model.KList{ Key: model.ColumnsKeyUnique, Multi: (keyNameCount[v.KeyName] > 1), KeyName: v.KeyName, + KeyType: v.IndexType, }) } } @@ -173,6 +184,7 @@ func (m *mysqlModel) getTableElement(orm *mysqldb.MySqlDB, tab string) (el []mod Key: model.ColumnsKeyIndex, Multi: true, KeyName: v.KeyName, + KeyType: v.IndexType, }) } } diff --git a/data/view/model/model.go b/data/view/model/model.go index 2d6b327..087c06c 100644 --- a/data/view/model/model.go +++ b/data/view/model/model.go @@ -91,7 +91,11 @@ func (m *_Model) genTableElement(cols []ColumnsInfo) (el []genstruct.GenElement) case ColumnsKeyUnique: // unique key.唯一索引 tmp.AddTag(_tagGorm, "unique") case ColumnsKeyIndex: // index key.复合索引 - tmp.AddTag(_tagGorm, getUninStr("index", ":", v1.KeyName)) + if v1.KeyType=="FULLTEXT" { + tmp.AddTag(_tagGorm, getUninStr("index", ":", v1.KeyName)+",class:FULLTEXT") + }else{ + tmp.AddTag(_tagGorm, getUninStr("index", ":", v1.KeyName)) + } case ColumnsKeyUniqueIndex: // unique index key.唯一复合索引 tmp.AddTag(_tagGorm, getUninStr("uniqueIndex", ":", v1.KeyName)) } diff --git a/data/view/model/model_test.go b/data/view/model/model_test.go index 6e3c9a6..8e92422 100644 --- a/data/view/model/model_test.go +++ b/data/view/model/model_test.go @@ -22,8 +22,6 @@ func TestTools(t *testing.T) { list, _ := Generate(pkg) fmt.Println(list) - config.SetSingularTable(true) - config.SetSingularTable(true) config.SetForeignKey(true) list, _ = Generate(pkg) fmt.Println(list)