support blob
first char lowcase in arg
This commit is contained in:
@@ -35,6 +35,10 @@ var TypeMysqlDicMp = map[string]string{
|
||||
"tinytext": "string",
|
||||
"enum": "string",
|
||||
"time": "time.Time",
|
||||
"tinyblob": "[]byte",
|
||||
"blob": "[]byte",
|
||||
"mediumblob": "[]byte",
|
||||
"longblob": "[]byte",
|
||||
}
|
||||
|
||||
// TypeMysqlMatchMp Fuzzy Matching Types.模糊匹配类型
|
||||
|
||||
@@ -112,8 +112,8 @@ func (obj *_{{$obj.StructName}}Mgr) Gets() (results []*{{$obj.StructName}}, err
|
||||
//////////////////////////option case ////////////////////////////////////////////
|
||||
{{range $oem := $obj.Em}}
|
||||
// With{{$oem.ColStructName}} {{$oem.ColName}}获取 {{$oem.Notes}}
|
||||
func (obj *_{{$obj.StructName}}Mgr) With{{$oem.ColStructName}}({{$oem.ColStructName}} {{$oem.Type}}) Option {
|
||||
return optionFunc(func(o *options) { o.query["{{$oem.ColName}}"] = {{$oem.ColStructName}} })
|
||||
func (obj *_{{$obj.StructName}}Mgr) With{{$oem.ColStructName}}({{CapLowercase $oem.ColStructName}} {{$oem.Type}}) Option {
|
||||
return optionFunc(func(o *options) { o.query["{{$oem.ColName}}"] = {{CapLowercase $oem.ColStructName}} })
|
||||
}
|
||||
{{end}}
|
||||
|
||||
@@ -149,21 +149,21 @@ func (obj *_{{$obj.StructName}}Mgr) GetByOptions(opts ...Option) (results []*{{$
|
||||
|
||||
{{range $oem := $obj.Em}}
|
||||
// GetFrom{{$oem.ColStructName}} 通过{{$oem.ColName}}获取内容 {{$oem.Notes}} {{if $oem.IsMulti}}
|
||||
func (obj *_{{$obj.StructName}}Mgr) GetFrom{{$oem.ColStructName}}({{$oem.ColStructName}} {{$oem.Type}}) (results []*{{$obj.StructName}}, err error) {
|
||||
err = obj.DB.Table(obj.GetTableName()).Where("{{$oem.ColName}} = ?", {{$oem.ColStructName}}).Find(&results).Error
|
||||
func (obj *_{{$obj.StructName}}Mgr) GetFrom{{$oem.ColStructName}}({{CapLowercase $oem.ColStructName}} {{$oem.Type}}) (results []*{{$obj.StructName}}, err error) {
|
||||
err = obj.DB.Table(obj.GetTableName()).Where("{{$oem.ColName}} = ?", {{CapLowercase $oem.ColStructName}}).Find(&results).Error
|
||||
{{GenPreloadList $obj.PreloadList true}}
|
||||
return
|
||||
}
|
||||
{{else}}
|
||||
func (obj *_{{$obj.StructName}}Mgr) GetFrom{{$oem.ColStructName}}({{$oem.ColStructName}} {{$oem.Type}}) (result {{$obj.StructName}}, err error) {
|
||||
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
|
||||
{{GenPreloadList $obj.PreloadList false}}
|
||||
return
|
||||
}
|
||||
{{end}}
|
||||
// GetBatchFrom{{$oem.ColStructName}} 批量唯一主键查找 {{$oem.Notes}}
|
||||
func (obj *_{{$obj.StructName}}Mgr) GetBatchFrom{{$oem.ColStructName}}({{$oem.ColStructName}}s []{{$oem.Type}}) (results []*{{$obj.StructName}}, err error) {
|
||||
err = obj.DB.Table(obj.GetTableName()).Where("{{$oem.ColName}} IN (?)", {{$oem.ColStructName}}s).Find(&results).Error
|
||||
func (obj *_{{$obj.StructName}}Mgr) GetBatchFrom{{$oem.ColStructName}}({{CapLowercase $oem.ColStructName}}s []{{$oem.Type}}) (results []*{{$obj.StructName}}, err error) {
|
||||
err = obj.DB.Table(obj.GetTableName()).Where("{{$oem.ColName}} IN (?)", {{CapLowercase $oem.ColStructName}}s).Find(&results).Error
|
||||
{{GenPreloadList $obj.PreloadList true}}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -34,6 +34,17 @@ func titleCase(name string) string {
|
||||
return string(vv)
|
||||
}
|
||||
|
||||
func CapLowercase(name string) string {
|
||||
vv := []rune(name)
|
||||
if len(vv) > 0 {
|
||||
if bool(vv[0] >= 'A' && vv[0] <= 'Z') { // title case.首字母大写
|
||||
vv[0] += 32
|
||||
}
|
||||
}
|
||||
|
||||
return string(vv)
|
||||
}
|
||||
|
||||
// getTypeName Type acquisition filtering.类型获取过滤
|
||||
func getTypeName(name string) string {
|
||||
// Precise matching first.先精确匹配
|
||||
@@ -144,7 +155,7 @@ func GenFListIndex(info FList, status int) string {
|
||||
{
|
||||
var strs []string
|
||||
for _, v := range info.Kem {
|
||||
strs = append(strs, fmt.Sprintf("%v %v ", v.ColStructName, v.Type))
|
||||
strs = append(strs, fmt.Sprintf("%v %v ", CapLowercase(v.ColStructName), v.Type))
|
||||
}
|
||||
return strings.Join(strs, ",")
|
||||
}
|
||||
@@ -160,7 +171,7 @@ func GenFListIndex(info FList, status int) string {
|
||||
{
|
||||
var strs []string
|
||||
for _, v := range info.Kem {
|
||||
strs = append(strs, v.ColStructName)
|
||||
strs = append(strs, CapLowercase(v.ColStructName))
|
||||
}
|
||||
return strings.Join(strs, " , ")
|
||||
}
|
||||
|
||||
@@ -296,9 +296,8 @@ func (m *_Model) generateFunc() (genOut []GenOutInfo) {
|
||||
data.Primay = append(data.Primay, unique...)
|
||||
data.Primay = append(data.Primay, uniqueIndex...)
|
||||
data.Index = append(data.Index, index...)
|
||||
|
||||
tmpl, err := template.New("gen_logic").
|
||||
Funcs(template.FuncMap{"GenPreloadList": GenPreloadList, "GenFListIndex": GenFListIndex}).
|
||||
Funcs(template.FuncMap{"GenPreloadList": GenPreloadList, "GenFListIndex": GenFListIndex, "CapLowercase": CapLowercase}).
|
||||
Parse(genfunc.GetGenLogicTemp())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
Reference in New Issue
Block a user