MCPcopy
hub / github.com/sqlc-dev/sqlc / Format

Method Format

internal/sql/ast/a_expr.go:36–107  ·  view source on GitHub ↗
(buf *TrackedBuffer, d format.Dialect)

Source from the content-addressed store, hash-verified

34}
35
36func (n *A_Expr) Format(buf *TrackedBuffer, d format.Dialect) {
37 if n == nil {
38 return
39 }
40
41 // Check for named parameter first (works regardless of Kind)
42 if name, ok := n.isNamedParam(); ok {
43 buf.WriteString(d.NamedParam(name))
44 return
45 }
46
47 switch n.Kind {
48 case A_Expr_Kind_IN:
49 buf.astFormat(n.Lexpr, d)
50 buf.WriteString(" IN (")
51 buf.astFormat(n.Rexpr, d)
52 buf.WriteString(")")
53 case A_Expr_Kind_LIKE:
54 buf.astFormat(n.Lexpr, d)
55 buf.WriteString(" LIKE ")
56 buf.astFormat(n.Rexpr, d)
57 case A_Expr_Kind_ILIKE:
58 buf.astFormat(n.Lexpr, d)
59 buf.WriteString(" ILIKE ")
60 buf.astFormat(n.Rexpr, d)
61 case A_Expr_Kind_SIMILAR:
62 buf.astFormat(n.Lexpr, d)
63 buf.WriteString(" SIMILAR TO ")
64 buf.astFormat(n.Rexpr, d)
65 case A_Expr_Kind_BETWEEN:
66 buf.astFormat(n.Lexpr, d)
67 buf.WriteString(" BETWEEN ")
68 if l, ok := n.Rexpr.(*List); ok && len(l.Items) == 2 {
69 buf.astFormat(l.Items[0], d)
70 buf.WriteString(" AND ")
71 buf.astFormat(l.Items[1], d)
72 }
73 case A_Expr_Kind_NOT_BETWEEN:
74 buf.astFormat(n.Lexpr, d)
75 buf.WriteString(" NOT BETWEEN ")
76 if l, ok := n.Rexpr.(*List); ok && len(l.Items) == 2 {
77 buf.astFormat(l.Items[0], d)
78 buf.WriteString(" AND ")
79 buf.astFormat(l.Items[1], d)
80 }
81 case A_Expr_Kind_DISTINCT:
82 buf.astFormat(n.Lexpr, d)
83 buf.WriteString(" IS DISTINCT FROM ")
84 buf.astFormat(n.Rexpr, d)
85 case A_Expr_Kind_NOT_DISTINCT:
86 buf.astFormat(n.Lexpr, d)
87 buf.WriteString(" IS NOT DISTINCT FROM ")
88 buf.astFormat(n.Rexpr, d)
89 case A_Expr_Kind_NULLIF:
90 buf.WriteString("NULLIF(")
91 buf.astFormat(n.Lexpr, d)
92 buf.WriteString(", ")
93 buf.astFormat(n.Rexpr, d)

Callers

nothing calls this directly

Calls 4

isNamedParamMethod · 0.95
setFunction · 0.85
astFormatMethod · 0.80
NamedParamMethod · 0.65

Tested by

no test coverage detected