add 'DEFAULT NULL' to point
添加默认值为null 转换成指针类型
This commit is contained in:
@@ -55,22 +55,39 @@ func FilterKeywords(src string) string {
|
||||
}
|
||||
|
||||
// getTypeName Type acquisition filtering.类型获取过滤
|
||||
func getTypeName(name string) string {
|
||||
func getTypeName(name string, isNull bool) string {
|
||||
// Precise matching first.先精确匹配
|
||||
if v, ok := cnf.TypeMysqlDicMp[name]; ok {
|
||||
return v
|
||||
return fixNullToPorint(v, isNull)
|
||||
}
|
||||
|
||||
// Fuzzy Regular Matching.模糊正则匹配
|
||||
for k, v := range cnf.TypeMysqlMatchMp {
|
||||
if ok, _ := regexp.MatchString(k, name); ok {
|
||||
return v
|
||||
return fixNullToPorint(v, isNull)
|
||||
}
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("type (%v) not match in any way.maybe need to add on (https://github.com/xxjwxc/gormt/blob/master/data/view/cnf/def.go)", name))
|
||||
}
|
||||
|
||||
// 过滤null point 类型
|
||||
func fixNullToPorint(name string, isNull bool) string {
|
||||
if isNull && config.GetIsNullToPoint() {
|
||||
if strings.HasPrefix(name, "uint") {
|
||||
return "*" + name
|
||||
}
|
||||
if strings.HasPrefix(name, "int") {
|
||||
return "*" + name
|
||||
}
|
||||
if strings.HasPrefix(name, "float") {
|
||||
return "*" + name
|
||||
}
|
||||
}
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
func getUninStr(left, middle, right string) string {
|
||||
re := left
|
||||
if len(right) > 0 {
|
||||
|
||||
@@ -81,7 +81,7 @@ func (m *_Model) genTableElement(cols []ColumnsInfo) (el []genstruct.GenElement)
|
||||
} else {
|
||||
tmp.SetName(getCamelName(v.Name))
|
||||
tmp.SetNotes(v.Notes)
|
||||
tmp.SetType(getTypeName(v.Type))
|
||||
tmp.SetType(getTypeName(v.Type, v.IsNull))
|
||||
for _, v1 := range v.Index {
|
||||
switch v1.Key {
|
||||
// case ColumnsKeyDefault:
|
||||
@@ -243,7 +243,7 @@ func (m *_Model) generateFunc() (genOut []GenOutInfo) {
|
||||
pkg.AddImport(`"time"`)
|
||||
buildFList(&primary, ColumnsKeyPrimary, "", "int64", "id")
|
||||
} else {
|
||||
typeName := getTypeName(el.Type)
|
||||
typeName := getTypeName(el.Type, el.IsNull)
|
||||
isMulti := (len(el.Index) == 0)
|
||||
for _, v1 := range el.Index {
|
||||
if v1.Multi {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func TestTypeName(t *testing.T) {
|
||||
fmt.Println(getTypeName("tinyint"))
|
||||
fmt.Println(getTypeName("tinyint", true))
|
||||
}
|
||||
|
||||
func TestTools(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user