Skip to content

Commit

Permalink
feat: return single data use Take()
Browse files Browse the repository at this point in the history
  • Loading branch information
idersec authored and tr1v3r committed Sep 15, 2021
1 parent a2f692a commit 32904bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions internal/check/checkinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ func (m *InterfaceMethod) HasNeedNewResult() bool {
return !m.ResultData.IsArray && ((m.ResultData.IsNull() && m.ResultData.IsTime()) || m.ResultData.IsMap())
}

// HasNeedNewResult need pointer or not
func (m *InterfaceMethod) GormRunMethodName() string {
if m.ResultData.IsArray {
return "Find"
}
return "Take"
}

// IsRepeatFromDifferentInterface check different interface has same mame method
func (m *InterfaceMethod) IsRepeatFromDifferentInterface(newMethod *InterfaceMethod) bool {
return m.MethodName == newMethod.MethodName && m.InterfaceName != newMethod.InterfaceName && m.TargetStruct == newMethod.TargetStruct
Expand Down
2 changes: 1 addition & 1 deletion internal/template/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func ({{.S}} {{.TargetStruct}}Do){{.MethodName}}({{.GetParamInTmpl}})({{.GetResu
{{end}}
{{if .HasNeedNewResult}}result ={{if .ResultData.IsMap}}make{{else}}new{{end}}({{if ne .ResultData.Package ""}}{{.ResultData.Package}}.{{end}}{{.ResultData.Type}}){{end}}
{{.ExecuteResult}} = {{.S}}.UnderlyingDB().{{.GormOption}}(generateSQL{{if .HasSqlData}},params{{end}}){{if not .ResultData.IsNull}}.Find({{if .HasGotPoint}}&{{end}}{{.ResultData.Name}}){{end}}.Error
{{.ExecuteResult}} = {{.S}}.UnderlyingDB().{{.GormOption}}(generateSQL{{if .HasSqlData}},params{{end}}){{if not .ResultData.IsNull}}.{{.GormRunMethodName}}({{if .HasGotPoint}}&{{end}}{{.ResultData.Name}}){{end}}.Error
return
}
Expand Down

0 comments on commit 32904bb

Please sign in to comment.