File tree 1 file changed +36
-0
lines changed
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -253,6 +253,42 @@ func TestTqla(t *testing.T) {
253
253
10 ,
254
254
},
255
255
},
256
+ {
257
+ name : "order by" ,
258
+ templateSql : `
259
+ {{ $len := len .Columns }}
260
+ SELECT * FROM t1 WHERE username = {{ .Username }}
261
+ {{ if gt $len 0 }}
262
+ ORDER BY
263
+ {{ $pos := 0}}
264
+ {{ range $i, $v := .Columns }}
265
+ {{ if eq $v "username" }}
266
+ username
267
+ {{ end }}
268
+ {{ $pos = add $pos 1 }}
269
+ {{ if eq $pos $len }}{{ else }},{{ end }}
270
+ {{ end }}
271
+ {{ if eq .Order "ASC" }}
272
+ ASC
273
+ {{ else }}
274
+ DESC
275
+ {{ end }}
276
+ {{ end }}` ,
277
+
278
+ data : & struct {
279
+ Username string
280
+ Order string
281
+ Columns []string
282
+ }{
283
+ Username : "test" ,
284
+ Order : "ASC" ,
285
+ Columns : []string {"username" },
286
+ },
287
+ options : []Option {
288
+ WithPlaceHolder (Dollar ), WithFuncMap (funcs )},
289
+ expectedSql : `SELECT * FROM t1 WHERE username = $1 ORDER BY username ASC` ,
290
+ expectedArgs : []any {"test" },
291
+ },
256
292
}
257
293
258
294
for _ , testCase := range testCases {
You can’t perform that action at this time.
0 commit comments