@@ -11,6 +11,7 @@ import (
1111
1212 "github.com/kyleconroy/sqlc/internal/codegen"
1313 "github.com/kyleconroy/sqlc/internal/config"
14+ "github.com/kyleconroy/sqlc/internal/metadata"
1415)
1516
1617type Generateable interface {
@@ -124,6 +125,11 @@ func interfaceImports(r Generateable, settings config.CombinedSettings) fileImpo
124125 if uses ("sql.Null" ) {
125126 std ["database/sql" ] = struct {}{}
126127 }
128+ for _ , q := range gq {
129+ if q .Cmd == metadata .CmdExecResult {
130+ std ["database/sql" ] = struct {}{}
131+ }
132+ }
127133 if uses ("json.RawMessage" ) {
128134 std ["encoding/json" ] = struct {}{}
129135 }
@@ -324,6 +330,11 @@ func queryImports(r Generateable, settings config.CombinedSettings, filename str
324330 if uses ("sql.Null" ) {
325331 std ["database/sql" ] = struct {}{}
326332 }
333+ for _ , q := range gq {
334+ if q .Cmd == metadata .CmdExecResult {
335+ std ["database/sql" ] = struct {}{}
336+ }
337+ }
327338 if uses ("json.RawMessage" ) {
328339 std ["encoding/json" ] = struct {}{}
329340 }
@@ -518,6 +529,9 @@ type Querier interface {
518529 {{- if eq .Cmd ":execrows"}}
519530 {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (int64, error)
520531 {{- end}}
532+ {{- if eq .Cmd ":execresult"}}
533+ {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (sql.Result, error)
534+ {{- end}}
521535 {{- end}}
522536}
523537
@@ -684,6 +698,18 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (int64, er
684698 return result.RowsAffected()
685699}
686700{{end}}
701+
702+ {{if eq .Cmd ":execresult"}}
703+ {{range .Comments}}//{{.}}
704+ {{end -}}
705+ func (q *Queries) {{.MethodName}}(ctx context.Context, {{.Arg.Pair}}) (sql.Result, error) {
706+ {{- if $.EmitPreparedQueries}}
707+ return := q.exec(ctx, q.{{.FieldName}}, {{.ConstantName}}, {{.Arg.Params}})
708+ {{- else}}
709+ return q.db.ExecContext(ctx, {{.ConstantName}}, {{.Arg.Params}})
710+ {{- end}}
711+ }
712+ {{end}}
687713{{end}}
688714{{end}}
689715{{end}}
0 commit comments