mirror of
https://github.com/ent/ent.git
synced 2026-04-28 21:50:56 +03:00
dialect/sql/sqljson: add {lt,lte} to predicates (#757)
This commit is contained in:
@@ -62,7 +62,8 @@ func ValueGT(column string, arg interface{}, opts ...Option) *sql.Predicate {
|
||||
}
|
||||
|
||||
// ValueGTE return a predicate for checking that a JSON value
|
||||
// (returned by the path) is greater than the given argument.
|
||||
// (returned by the path) is greater than or equal to the given
|
||||
// argument.
|
||||
//
|
||||
// sqljson.ValueGTE("a", 1, sqljson.Path("b"))
|
||||
//
|
||||
@@ -73,6 +74,31 @@ func ValueGTE(column string, arg interface{}, opts ...Option) *sql.Predicate {
|
||||
})
|
||||
}
|
||||
|
||||
// ValueLT return a predicate for checking that a JSON value
|
||||
// (returned by the path) is less than the given argument.
|
||||
//
|
||||
// sqljson.ValueLT("a", 1, sqljson.Path("b"))
|
||||
//
|
||||
func ValueLT(column string, arg interface{}, opts ...Option) *sql.Predicate {
|
||||
return sql.P(func(b *sql.Builder) {
|
||||
WritePath(b, column, opts...)
|
||||
b.WriteOp(sql.OpLT).Arg(arg)
|
||||
})
|
||||
}
|
||||
|
||||
// ValueLTE return a predicate for checking that a JSON value
|
||||
// (returned by the path) is less than or equal to the given
|
||||
// argument.
|
||||
//
|
||||
// sqljson.ValueLTE("a", 1, sqljson.Path("b"))
|
||||
//
|
||||
func ValueLTE(column string, arg interface{}, opts ...Option) *sql.Predicate {
|
||||
return sql.P(func(b *sql.Builder) {
|
||||
WritePath(b, column, opts...)
|
||||
b.WriteOp(sql.OpLTE).Arg(arg)
|
||||
})
|
||||
}
|
||||
|
||||
// WritePath writes the JSON path from the given options to the SQL builder.
|
||||
//
|
||||
// sqljson.WritePath(b, Path("a", "b", "[1]", "c"), Cast("int"))
|
||||
|
||||
Reference in New Issue
Block a user