mirror of
https://github.com/ent/ent.git
synced 2026-04-28 13:40:56 +03:00
dialect/sql/sqljson: add all predicates for length (#764)
This commit is contained in:
@@ -106,6 +106,11 @@ func ValueLTE(column string, arg interface{}, opts ...Option) *sql.Predicate {
|
||||
})
|
||||
}
|
||||
|
||||
// LenEQ return a predicate for checking that an array length
|
||||
// of a JSON (returned by the path) is equal to the given argument.
|
||||
//
|
||||
// sqljson.LenEQ("a", 1, sqljson.Path("b"))
|
||||
//
|
||||
func LenEQ(column string, size int, opts ...Option) *sql.Predicate {
|
||||
return sql.P(func(b *sql.Builder) {
|
||||
LenPath(b, column, opts...)
|
||||
@@ -113,6 +118,70 @@ func LenEQ(column string, size int, opts ...Option) *sql.Predicate {
|
||||
})
|
||||
}
|
||||
|
||||
// LenNEQ return a predicate for checking that an array length
|
||||
// of a JSON (returned by the path) is not equal to the given argument.
|
||||
//
|
||||
// sqljson.LenEQ("a", 1, sqljson.Path("b"))
|
||||
//
|
||||
func LenNEQ(column string, size int, opts ...Option) *sql.Predicate {
|
||||
return sql.P(func(b *sql.Builder) {
|
||||
LenPath(b, column, opts...)
|
||||
b.WriteOp(sql.OpNEQ).Arg(size)
|
||||
})
|
||||
}
|
||||
|
||||
// LenGT return a predicate for checking that an array length
|
||||
// of a JSON (returned by the path) is greater than the given
|
||||
// argument.
|
||||
//
|
||||
// sqljson.LenGT("a", 1, sqljson.Path("b"))
|
||||
//
|
||||
func LenGT(column string, size int, opts ...Option) *sql.Predicate {
|
||||
return sql.P(func(b *sql.Builder) {
|
||||
LenPath(b, column, opts...)
|
||||
b.WriteOp(sql.OpGT).Arg(size)
|
||||
})
|
||||
}
|
||||
|
||||
// LenGTE return a predicate for checking that an array length
|
||||
// of a JSON (returned by the path) is greater than or equal to
|
||||
// the given argument.
|
||||
//
|
||||
// sqljson.LenGTE("a", 1, sqljson.Path("b"))
|
||||
//
|
||||
func LenGTE(column string, size int, opts ...Option) *sql.Predicate {
|
||||
return sql.P(func(b *sql.Builder) {
|
||||
LenPath(b, column, opts...)
|
||||
b.WriteOp(sql.OpGTE).Arg(size)
|
||||
})
|
||||
}
|
||||
|
||||
// LenLT return a predicate for checking that an array length
|
||||
// of a JSON (returned by the path) is less than the given
|
||||
// argument.
|
||||
//
|
||||
// sqljson.LenLT("a", 1, sqljson.Path("b"))
|
||||
//
|
||||
func LenLT(column string, size int, opts ...Option) *sql.Predicate {
|
||||
return sql.P(func(b *sql.Builder) {
|
||||
LenPath(b, column, opts...)
|
||||
b.WriteOp(sql.OpLT).Arg(size)
|
||||
})
|
||||
}
|
||||
|
||||
// LenLTE return a predicate for checking that an array length
|
||||
// of a JSON (returned by the path) is less than or equal to
|
||||
// the given argument.
|
||||
//
|
||||
// sqljson.LenLTE("a", 1, sqljson.Path("b"))
|
||||
//
|
||||
func LenLTE(column string, size int, opts ...Option) *sql.Predicate {
|
||||
return sql.P(func(b *sql.Builder) {
|
||||
LenPath(b, column, opts...)
|
||||
b.WriteOp(sql.OpLTE).Arg(size)
|
||||
})
|
||||
}
|
||||
|
||||
// ValuePath writes to the given SQL builder the JSON path for
|
||||
// getting the value of a given JSON path.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user