dialect/sql/sqljson: add all predicates for length (#764)

This commit is contained in:
Ariel Mashraki
2020-09-15 12:38:36 +03:00
committed by GitHub
parent 3578d73a8f
commit 2c0d7e5a42
2 changed files with 84 additions and 0 deletions

View File

@@ -132,6 +132,21 @@ func TestWritePath(t *testing.T) {
wantQuery: "SELECT * FROM `users` WHERE JSON_ARRAY_LENGTH(`a`, \"$\") = ?",
wantArgs: []interface{}{1},
},
{
input: sql.Dialect(dialect.SQLite).
Select("*").
From(sql.Table("users")).
Where(
sql.Or(
sqljson.LenGT("a", 1, sqljson.Path("b")),
sqljson.LenGTE("a", 1, sqljson.Path("c")),
sqljson.LenLT("a", 1, sqljson.Path("d")),
sqljson.LenLTE("a", 1, sqljson.Path("e")),
),
),
wantQuery: "SELECT * FROM `users` WHERE JSON_ARRAY_LENGTH(`a`, \"$.b\") > ? OR JSON_ARRAY_LENGTH(`a`, \"$.c\") >= ? OR JSON_ARRAY_LENGTH(`a`, \"$.d\") < ? OR JSON_ARRAY_LENGTH(`a`, \"$.e\") <= ?",
wantArgs: []interface{}{1, 1, 1, 1},
},
}
for i, tt := range tests {
t.Run(strconv.Itoa(i), func(t *testing.T) {