@@ -31,8 +31,8 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{ dbarg }} {{.Arg.Pair}}
31
31
{{- if or (ne .Arg.Pair .Ret.Pair) (ne .Arg.DefineType .Ret.DefineType) }}
32
32
var {{.Ret.Name}} {{.Ret.Type}}
33
33
{{- end}}
34
- {{- if emitSchemaName }}
35
- err := row.Scan(strings.ReplaceAll( {{.Ret.Scan}}, "%s", schema) )
34
+ {{- if emitSchemaName }}
35
+ err := row.Scan({{.Ret.Scan}})
36
36
{{- else }}
37
37
err := row.Scan({{.Ret.Scan}})
38
38
{{- end }}
@@ -58,6 +58,8 @@ type {{.MethodName}}FilterParams struct {
58
58
LikeParams []{{.MethodName}}Filter
59
59
SinceParams []{{.MethodName}}Filter
60
60
MaxParams []{{.MethodName}}Filter
61
+ SortParam string
62
+ SortOrder string
61
63
}
62
64
63
65
func (q *Queries) {{.MethodName}}(ctx context.Context, schema string, filterParams {{.MethodName}}FilterParams, {{ dbarg }} {{.Arg.Pair}}) ([]{{.Ret.DefineType}}, error) {;
@@ -213,14 +215,16 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{ dbarg }} {{.Arg.Pair}}
213
215
{{- if emitSchemaName }}
214
216
query := strings.ReplaceAll({{.ConstantName}}, "%s", schema);
215
217
216
- // Extract the columns from the query;
217
- columns := columnRegex.FindString(query);
218
-
219
218
{{- /**
220
219
If the query has a filter, we need to add the filter to the query
221
220
and the query params.
222
221
*/}}
223
222
223
+ {{- if eq .Cmd ":many"}}
224
+
225
+ // Extract the columns from the query;
226
+ columns := columnRegex.FindString(query);
227
+
224
228
isFirstFilter := true;
225
229
var queryParams []interface{};
226
230
@@ -309,10 +313,25 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{ dbarg }} {{.Arg.Pair}}
309
313
queryParams = append(queryParams, filter.Value)
310
314
};
311
315
312
- {{- queryRetval . }} {{ queryMethod . }}(ctx, query, {{.Arg.Params}})
316
+ if filterParams.SortParam != "" {
317
+ query += " ORDER BY " + filterParams.SortParam + " " + filterParams.SortOrder
318
+ }
319
+
320
+ // If there is not the ; at the end, add it
321
+ if !strings.HasSuffix(query, ";") {
322
+ query += ";"
323
+ };
324
+
325
+ {{- queryRetval . }} {{ queryMethod . }}(ctx, query, queryParams...)
326
+
327
+ {{- end }}
313
328
314
329
{{- else }}
315
330
{{- queryRetval . }} {{ queryMethod . }}(ctx, {{.ConstantName}}, {{.Arg.Params}})
316
331
{{- end -}}
332
+
333
+ {{- if ne .Cmd ":many"}}
334
+ {{- queryRetval . }} {{ queryMethod . }}(ctx, query, {{.Arg.Params}})
335
+ {{- end -}}
317
336
{{- end -}}
318
337
{{end}}
0 commit comments