Skip to content

Commit bb83006

Browse files
authored
Merge pull request #26 from VauntDev/elewis-order-by-test
feat: add order by test
2 parents 7e11d50 + c6d421a commit bb83006

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tqla_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,42 @@ func TestTqla(t *testing.T) {
253253
10,
254254
},
255255
},
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+
},
256292
}
257293

258294
for _, testCase := range testCases {

0 commit comments

Comments
 (0)