add default set
添加默认值
This commit is contained in:
@@ -38,9 +38,10 @@ type TabInfo struct {
|
||||
// ColumnsInfo Columns list .表列信息
|
||||
type ColumnsInfo struct {
|
||||
BaseInfo
|
||||
Type string // Type.类型标记
|
||||
Index []KList // index list.index列表
|
||||
IsNull bool // null if db is set null
|
||||
Type string // Type.类型标记
|
||||
Default string // 默认值
|
||||
Index []KList // index list.index列表
|
||||
ForeignKeyList []ForeignKey // Foreign key list . 表的外键信息
|
||||
}
|
||||
|
||||
|
||||
@@ -52,3 +52,23 @@ func GetMysqlModel() model.IModel {
|
||||
//now just support mysql
|
||||
return &MySQLModel
|
||||
}
|
||||
|
||||
// FixElementNote 分析元素表注释
|
||||
func FixElementNote(em *model.ColumnsInfo, note string) {
|
||||
matches := noteRegex.FindStringSubmatch(note)
|
||||
if len(matches) < 2 {
|
||||
em.Notes = note
|
||||
return
|
||||
}
|
||||
em.Notes = note[len(matches[0]):]
|
||||
|
||||
list := strings.Split(matches[1], ";")
|
||||
for _, v := range list {
|
||||
tmp := strings.Split(v, ":")
|
||||
if len(tmp) == 2 {
|
||||
if strings.EqualFold(tmp[0], "default") { // 默认值
|
||||
em.Default = tmp[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package genmysql
|
||||
|
||||
import "regexp"
|
||||
|
||||
type keys struct {
|
||||
NonUnique int `gorm:"column:Non_unique"`
|
||||
KeyName string `gorm:"column:Key_name"`
|
||||
@@ -26,3 +28,5 @@ type genForeignKey struct {
|
||||
ReferencedTableName string `gorm:"column:referenced_table_name"` // Affected tables . 该索引受影响的表
|
||||
ReferencedColumnName string `gorm:"column:referenced_column_name"` // Which column of the affected table.该索引受影响的表的哪一列
|
||||
}
|
||||
|
||||
var noteRegex = regexp.MustCompile(`^\[@gormt\s(\S+)+\]`)
|
||||
|
||||
@@ -141,8 +141,8 @@ func getTableElement(orm *mysqldb.MySqlDB, tab string) (el []model.ColumnsInfo)
|
||||
for _, v := range list {
|
||||
var tmp model.ColumnsInfo
|
||||
tmp.Name = v.Field
|
||||
tmp.Notes = v.Desc
|
||||
tmp.Type = v.Type
|
||||
FixElementNote(&tmp, v.Desc)
|
||||
|
||||
// keys
|
||||
if keylist, ok := KeyColumnMp[v.Field]; ok { // maybe have index or key
|
||||
|
||||
@@ -107,6 +107,10 @@ func (m *_Model) genTableElement(cols []ColumnsInfo) (el []genstruct.GenElement)
|
||||
tmp.AddTag(_tagGorm, "not null")
|
||||
}
|
||||
}
|
||||
// default tag
|
||||
if len(v.Default) > 0 {
|
||||
tmp.AddTag(_tagGorm, "default:"+v.Default)
|
||||
}
|
||||
|
||||
// json tag
|
||||
if config.GetIsWEBTag() {
|
||||
@@ -116,6 +120,7 @@ func (m *_Model) genTableElement(cols []ColumnsInfo) (el []genstruct.GenElement)
|
||||
tmp.AddTag(_tagJSON, mybigcamel.UnMarshal(v.Name))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
el = append(el, tmp)
|
||||
|
||||
Reference in New Issue
Block a user