dialect/sql: allow creating predicate from raw expression (#1263)

This commit is contained in:
Ariel Mashraki
2021-02-19 17:29:16 +02:00
committed by GitHub
parent f9747bc1e6
commit d6f6c81a22
2 changed files with 11 additions and 3 deletions

View File

@@ -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"))

View File

@@ -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"))
})).