Skip to content

Commit 7b0a77e

Browse files
committed
Rewrited slices logic not replace them
1 parent 3b8d7ec commit 7b0a77e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

internal/codegen/golang/gen.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type tmplCtx struct {
4242
OmitSqlcVersion bool
4343
BuildTags string
4444
WrapErrors bool
45+
EmitSliceExpansion bool
4546
}
4647

4748
func (t *tmplCtx) OutputQuery(sourceName string) bool {
@@ -55,6 +56,10 @@ func (t *tmplCtx) codegenDbarg() string {
5556
return ""
5657
}
5758

59+
func (t *tmplCtx) shouldExpandSlices(q Query) bool {
60+
return t.EmitSliceExpansion && q.Arg.HasSqlcSlices()
61+
}
62+
5863
// Called as a global method since subtemplate queryCodeStdExec does not have
5964
// access to the toplevel tmplCtx
6065
func (t *tmplCtx) codegenEmitPreparedQueries() bool {
@@ -181,6 +186,7 @@ func generate(req *plugin.GenerateRequest, options *opts.Options, enums []Enum,
181186
EmitMethodsWithDBArgument: options.EmitMethodsWithDbArgument,
182187
EmitEnumValidMethod: options.EmitEnumValidMethod,
183188
EmitAllEnumValues: options.EmitAllEnumValues,
189+
EmitSliceExpansion: options.Engine != "ydb",
184190
UsesCopyFrom: usesCopyFrom(queries),
185191
UsesBatch: usesBatch(queries),
186192
SQLDriver: parseDriver(options.SqlPackage),
@@ -218,8 +224,6 @@ func generate(req *plugin.GenerateRequest, options *opts.Options, enums []Enum,
218224
}
219225
}
220226

221-
isYDBEngine := func() bool { return options.Engine == "ydb" }
222-
223227
funcMap := template.FuncMap{
224228
"lowerTitle": sdk.LowerTitle,
225229
"comment": sdk.DoubleSlashComment,
@@ -234,7 +238,7 @@ func generate(req *plugin.GenerateRequest, options *opts.Options, enums []Enum,
234238
"emitPreparedQueries": tctx.codegenEmitPreparedQueries,
235239
"queryMethod": tctx.codegenQueryMethod,
236240
"queryRetval": tctx.codegenQueryRetval,
237-
"isYDBEngine": isYDBEngine,
241+
"shouldExpandSlices": tctx.shouldExpandSlices,
238242
}
239243

240244
tmpl := template.Must(

internal/codegen/golang/templates/stdlib/queryCode.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{ dbarg }} {{.Arg.Pair}}
125125
{{end}}
126126

127127
{{define "queryCodeStdExec"}}
128-
{{- if and (not isYDBEngine) .Arg.HasSqlcSlices }}
128+
{{- if shouldExpandSlices . }}
129129
query := {{.ConstantName}}
130130
var queryParams []interface{}
131131
{{- if .Arg.Struct }}

0 commit comments

Comments
 (0)