add: INDEX FULLTEXT

add: Default value
master
young 4 years ago
parent db108519e9
commit acd9861d7f

@ -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. 基础属性

@ -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

@ -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,
})
}
}

@ -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))
}

@ -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)

Loading…
Cancel
Save