Repository navigation
Expand file tree
/
Copy pathbool_expr.go
More file actions
70 lines (65 loc) · 1.44 KB
/
Copy pathbool_expr.go
File metadata and controls
70 lines (65 loc) · 1.44 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package ast
import "github.com/sqlc-dev/sqlc/internal/sql/format"
type BoolExpr struct {
Tag NodeTag[BoolExpr] `json:"tag"`
Xpr Node `json:"xpr,omitempty"`
Boolop BoolExprType `json:"boolop"`
Args *List `json:"args,omitempty"`
Location int `json:"location"`
}
func (n *BoolExpr) Pos() int {
return n.Location
}
func (n *BoolExpr) Format(buf *TrackedBuffer, d format.Dialect) {
if n == nil {
return
}
switch n.Boolop {
case BoolExprTypeIsNull:
if items(n.Args) && len(n.Args.Items) > 0 {
buf.astFormat(n.Args.Items[0], d)
}
buf.WriteString(" IS NULL")
case BoolExprTypeIsNotNull:
if items(n.Args) && len(n.Args.Items) > 0 {
buf.astFormat(n.Args.Items[0], d)
}
buf.WriteString(" IS NOT NULL")
case BoolExprTypeNot:
// NOT expression: format as NOT <arg>
buf.WriteString("NOT ")
if items(n.Args) && len(n.Args.Items) > 0 {
buf.astFormat(n.Args.Items[0], d)
}
default:
var op string
switch n.Boolop {
case BoolExprTypeAnd:
op = "AND "
case BoolExprTypeOr:
op = "OR "
}
buf.WriteString("(")
buf.Group()
buf.Indent()
buf.Softline()
if items(n.Args) && op != "" {
first := true
for _, item := range n.Args.Items {
if _, ok := item.(*TODO); ok {
continue
}
if !first {
buf.Line()
buf.WriteString(op)
}
first = false
buf.astFormat(item, d)
}
}
buf.EndIndent()
buf.Softline()
buf.EndGroup()
buf.WriteString(")")
}
}