-
Notifications
You must be signed in to change notification settings - Fork 36
/
builder.go
54 lines (45 loc) · 1.23 KB
/
builder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package dialect
import (
"strings"
"github.com/stephenafamo/bob"
"github.com/stephenafamo/bob/expr"
)
//nolint:gochecknoglobals
var (
and = expr.Raw("AND")
betweenSymmetric = expr.Raw("BETWEEN")
notBetweenSymmetric = expr.Raw("NOT BETWEEN")
iLike = expr.Raw("ILIKE")
)
type Expression struct {
expr.Chain[Expression, Expression]
}
func (Expression) New(exp bob.Expression) Expression {
var b Expression
b.Base = exp
return b
}
// Implements fmt.Stringer()
func (x Expression) String() string {
w := strings.Builder{}
x.WriteSQL(&w, Dialect, 1) //nolint:errcheck
return w.String()
}
// BETWEEN SYMMETRIC a AND b
func (x Expression) BetweenSymmetric(a, b bob.Expression) Expression {
return expr.X[Expression, Expression](expr.Join{Exprs: []bob.Expression{
x.Base, betweenSymmetric, a, and, b,
}})
}
// NOT BETWEEN SYMMETRIC a AND b
func (x Expression) NotBetweenSymmetric(a, b bob.Expression) Expression {
return expr.X[Expression, Expression](expr.Join{Exprs: []bob.Expression{
x.Base, notBetweenSymmetric, a, and, b,
}})
}
// ILIKE val
func (x Expression) ILike(val bob.Expression) Expression {
return expr.X[Expression, Expression](expr.Join{Exprs: []bob.Expression{
x.Base, iLike, val,
}})
}