Filter keywords

过滤关键字
This commit is contained in:
谢小军
2020-05-11 15:16:24 +08:00
parent 89ef2282a9
commit a3901e56d2
5 changed files with 47 additions and 46 deletions

View File

@@ -43,19 +43,20 @@ var TypeMysqlDicMp = map[string]string{
// TypeMysqlMatchMp Fuzzy Matching Types.模糊匹配类型
var TypeMysqlMatchMp = map[string]string{
`^(tinyint)[(]\d+[)]`: "int8",
`^(tinyint)[(]\d+[)] unsigned`: "uint8",
`^(smallint)[(]\d+[)]`: "int16",
`^(int)[(]\d+[)]`: "int",
`^(bigint)[(]\d+[)]`: "int64",
`^(char)[(]\d+[)]`: "string",
`^(enum)[(](.)+[)]`: "string",
`^(varchar)[(]\d+[)]`: "string",
`^(varbinary)[(]\d+[)]`: "[]byte",
`^(binary)[(]\d+[)]`: "[]byte",
`^(decimal)[(]\d+,\d+[)]`: "float64",
`^(mediumint)[(]\d+[)]`: "string",
`^(double)[(]\d+,\d+[)]`: "float64",
`^(float)[(]\d+,\d+[)]`: "float64",
`^(datetime)[(]\d+[)]`: "time.Time",
`^(tinyint)[(]\d+[)]`: "int8",
`^(tinyint)[(]\d+[)] unsigned`: "uint8",
`^(smallint)[(]\d+[)]`: "int16",
`^(int)[(]\d+[)]`: "int",
`^(bigint)[(]\d+[)]`: "int64",
`^(char)[(]\d+[)]`: "string",
`^(enum)[(](.)+[)]`: "string",
`^(varchar)[(]\d+[)]`: "string",
`^(varbinary)[(]\d+[)]`: "[]byte",
`^(binary)[(]\d+[)]`: "[]byte",
`^(decimal)[(]\d+,\d+[)]`: "float64",
`^(mediumint)[(]\d+[)]`: "string",
`^(double)[(]\d+,\d+[)]`: "float64",
`^(float)[(]\d+,\d+[)]`: "float64",
`^(float)[(]\d+,\d+[)] unsigned`: "float64",
`^(datetime)[(]\d+[)]`: "time.Time",
}

View File

@@ -156,7 +156,7 @@ func (obj *_{{$obj.StructName}}Mgr) GetFrom{{$oem.ColStructName}}({{CapLowercase
}
{{else}}
func (obj *_{{$obj.StructName}}Mgr) GetFrom{{$oem.ColStructName}}({{CapLowercase $oem.ColStructName}} {{$oem.Type}}) (result {{$obj.StructName}}, err error) {
err = obj.DB.Table(obj.GetTableName()).Where("{{$oem.ColName}} = ?", {{$oem.ColStructName}}).Find(&result).Error
err = obj.DB.Table(obj.GetTableName()).Where("{{$oem.ColName}} = ?", {{CapLowercase $oem.ColStructName}}).Find(&result).Error
{{GenPreloadList $obj.PreloadList false}}
return
}

View File

@@ -11,6 +11,7 @@ import (
"github.com/xxjwxc/gormt/data/view/cnf"
"github.com/xxjwxc/gormt/data/view/genfunc"
"github.com/xxjwxc/public/mybigcamel"
"github.com/xxjwxc/public/tools"
)
// getCamelName Big Hump or Capital Letter.大驼峰或者首字母大写
@@ -41,7 +42,16 @@ func CapLowercase(name string) string { // IDAPIID == > idAPIID
return ""
}
return list[0] + name[len(list[0]):]
re := list[0] + name[len(list[0]):]
return FilterKeywords(re)
}
func FilterKeywords(src string) string {
if tools.IsKeywords(src) {
return "_" + src
}
return src
}
// getTypeName Type acquisition filtering.类型获取过滤