Skip to content

Commit

Permalink
support blob
Browse files Browse the repository at this point in the history
first char lowcase in arg
  • Loading branch information
lijunlong committed Apr 21, 2020
1 parent 44ed225 commit b994245
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
4 changes: 4 additions & 0 deletions data/view/cnf/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.模糊匹配类型
Expand Down
14 changes: 7 additions & 7 deletions data/view/genfunc/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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
}
Expand Down
15 changes: 13 additions & 2 deletions data/view/model/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.先精确匹配
Expand Down Expand Up @@ -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, ",")
}
Expand All @@ -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, " , ")
}
Expand Down
3 changes: 1 addition & 2 deletions data/view/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b994245

Please sign in to comment.