colname add ``

给导出列名添加``符
This commit is contained in:
xxj
2021-02-19 18:03:04 +08:00
parent ea7c73db90
commit 0e2a3e4553
4 changed files with 7 additions and 5 deletions

View File

@@ -148,7 +148,7 @@ func (obj *_{{$obj.StructName}}Mgr) Gets() (results []*{{$obj.StructName}}, err
{{range $oem := $obj.Em}}
// With{{$oem.ColStructName}} {{$oem.ColName}}获取 {{$oem.Notes}}
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}} })
return optionFunc(func(o *options) { o.query["{{$oem.ColNameEx}}"] = {{CapLowercase $oem.ColStructName}} })
}
{{end}}
@@ -184,20 +184,20 @@ 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}}({{CapLowercase $oem.ColStructName}} {{$oem.Type}}) (results []*{{$obj.StructName}}, err error) {
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("{{$oem.ColName}} = ?", {{CapLowercase $oem.ColStructName}}).Find(&results).Error
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("{{$oem.ColNameEx}} = ?", {{CapLowercase $oem.ColStructName}}).Find(&results).Error
{{GenPreloadList $obj.PreloadList true}}
return
}
{{else}}
func (obj *_{{$obj.StructName}}Mgr) GetFrom{{$oem.ColStructName}}({{CapLowercase $oem.ColStructName}} {{$oem.Type}}) (result {{$obj.StructName}}, err error) {
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("{{$oem.ColName}} = ?", {{CapLowercase $oem.ColStructName}}).Find(&result).Error
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("{{$oem.ColNameEx}} = ?", {{CapLowercase $oem.ColStructName}}).Find(&result).Error
{{GenPreloadList $obj.PreloadList false}}
return
}
{{end}}
// GetBatchFrom{{$oem.ColStructName}} 批量唯一主键查找 {{$oem.Notes}}
func (obj *_{{$obj.StructName}}Mgr) GetBatchFrom{{$oem.ColStructName}}({{CapLowercase $oem.ColStructName}}s []{{$oem.Type}}) (results []*{{$obj.StructName}}, err error) {
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("{{$oem.ColName}} IN (?)", {{CapLowercase $oem.ColStructName}}s).Find(&results).Error
err = obj.DB.WithContext(obj.ctx).Table(obj.GetTableName()).Where("{{$oem.ColNameEx}} IN (?)", {{CapLowercase $oem.ColStructName}}s).Find(&results).Error
{{GenPreloadList $obj.PreloadList true}}
return
}

View File

@@ -189,7 +189,7 @@ func GenFListIndex(info FList, status int) string {
{
var strs []string
for _, v := range info.Kem {
strs = append(strs, fmt.Sprintf("%v = ?", v.ColName))
strs = append(strs, fmt.Sprintf("`%v` = ?", v.ColName))
}
return strings.Join(strs, " AND ")
}

View File

@@ -106,6 +106,7 @@ type EmInfo struct {
Notes string // 注释
Type string // 类型
ColName string // 列名
ColNameEx string // `列名`
ColStructName string // 列结构体
}

View File

@@ -297,6 +297,7 @@ func (m *_Model) generateFunc() (genOut []GenOutInfo) {
Notes: fixNotes(el.Notes),
Type: typeName, // Type.类型标记
ColName: el.Name,
ColNameEx: fmt.Sprintf("`%v`", el.Name),
ColStructName: getCamelName(el.Name),
})
if v2, ok := cnf.EImportsHead[typeName]; ok {