mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
dialect/sql: allow creating predicate from raw expression (#1263)
This commit is contained in:
@@ -891,6 +891,16 @@ func P(fns ...func(*Builder)) *Predicate {
|
||||
return &Predicate{fns: fns}
|
||||
}
|
||||
|
||||
// ExprP creates a new predicate from the given expression.
|
||||
//
|
||||
// ExprP("A = ? AND B > ?", args...)
|
||||
//
|
||||
func ExprP(exr string, args ...interface{}) *Predicate {
|
||||
return P(func(b *Builder) {
|
||||
b.Join(Expr(exr, args...))
|
||||
})
|
||||
}
|
||||
|
||||
// Or combines all given predicates with OR between them.
|
||||
//
|
||||
// Or(EQ("name", "foo"), EQ("name", "bar"))
|
||||
|
||||
@@ -1376,9 +1376,7 @@ WHERE
|
||||
input: Dialect(dialect.Postgres).
|
||||
Select("*").
|
||||
From(Table("users")).
|
||||
Where(P(func(b *Builder) {
|
||||
b.Join(Expr("name = $1", "pedro"))
|
||||
})).
|
||||
Where(ExprP("name = $1", "pedro")).
|
||||
Where(P(func(b *Builder) {
|
||||
b.Join(Expr("name = $2", "pedro"))
|
||||
})).
|
||||
|
||||
Reference in New Issue
Block a user