dialect/sql/sqljson: support for order by value and length (#3278)

This commit is contained in:
Ariel Mashraki
2023-01-26 12:20:31 +02:00
committed by GitHub
parent 604c4942a4
commit 433609444c
6 changed files with 258 additions and 81 deletions

View File

@@ -383,6 +383,15 @@ func TestWritePath(t *testing.T) {
wantQuery: "SELECT * FROM `users` WHERE JSON_EXTRACT(`a`, '$.\"foo-bar\".\"3000\"') IN (?, ?)",
wantArgs: []any{1, 2},
},
{
input: sql.Dialect(dialect.MySQL).
Select("*").
From(sql.Table("users")).
OrderExpr(
sqljson.LenPath("a", sqljson.Path("b")),
),
wantQuery: "SELECT * FROM `users` ORDER BY JSON_LENGTH(`a`, '$.b')",
},
}
for i, tt := range tests {
t.Run(strconv.Itoa(i), func(t *testing.T) {