Skip to content

Commit

Permalink
allow terminating loop by returning error
Browse files Browse the repository at this point in the history
  • Loading branch information
rucciva committed Apr 26, 2024
1 parent 5572e43 commit b133905
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions internal/templates/stdlib/queryCode.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{ dbarg }} {{.Arg.Pair}}
{{if eq .Cmd ":many"}}
{{range .Comments}}//{{.}}
{{end -}}
func (q *Queries) {{.MethodName}}(ctx context.Context, {{ dbarg }} {{.Arg.Pair}} {{if ne .Arg.Pair "" }},{{end}} {{ .Ret.Name }}OptionalInitFunc func(*{{.Ret.DefineType}}), {{ .Ret.Name }}OptionalFilterFunc func({{.Ret.DefineType}}) bool) ([]{{.Ret.DefineType}}, error) {
func (q *Queries) {{.MethodName}}(ctx context.Context, {{ dbarg }} {{.Arg.Pair}} {{if ne .Arg.Pair "" }},{{end}} {{ .Ret.Name }}OptionalInitFunc func(*{{.Ret.DefineType}}), {{ .Ret.Name }}OptionalFilterFunc func({{.Ret.DefineType}}) (bool,error)) ([]{{.Ret.DefineType}}, error) {
{{- template "queryCodeStdExec" . }}
if err != nil {
return nil, err
Expand All @@ -60,9 +60,16 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{ dbarg }} {{.Arg.Pair}}
return nil, err
}

if {{ .Ret.Name }}OptionalFilterFunc != nil && !{{ .Ret.Name }}OptionalFilterFunc({{.Ret.ReturnName}}) {
continue
if {{ .Ret.Name }}OptionalFilterFunc != nil {
add, err := {{ .Ret.Name }}OptionalFilterFunc({{.Ret.ReturnName}})
if err != nil {
return nil, err
}
if !add {
continue
}
}

items = append(items, {{.Ret.ReturnName}})
}
if err := rows.Close(); err != nil {
Expand Down

0 comments on commit b133905

Please sign in to comment.