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

Method Format

internal/sql/ast/on_conflict_clause.go:25–61  ·  view source on GitHub ↗
(buf *TrackedBuffer, d format.Dialect)

Source from the content-addressed store, hash-verified

23)
24
25func (n *OnConflictClause) Format(buf *TrackedBuffer, d format.Dialect) {
26 if n == nil {
27 return
28 }
29 buf.WriteString("ON CONFLICT ")
30 if n.Infer != nil {
31 buf.astFormat(n.Infer, d)
32 buf.WriteString(" ")
33 }
34 switch n.Action {
35 case OnConflictActionNothing:
36 buf.WriteString("DO NOTHING")
37 case OnConflictActionUpdate:
38 buf.WriteString("DO UPDATE SET ")
39 // Format as assignment list: name = val
40 if n.TargetList != nil {
41 for i, item := range n.TargetList.Items {
42 if i > 0 {
43 buf.WriteString(", ")
44 }
45 if rt, ok := item.(*ResTarget); ok {
46 if rt.Name != nil {
47 buf.WriteString(*rt.Name)
48 }
49 buf.WriteString(" = ")
50 buf.astFormat(rt.Val, d)
51 } else {
52 buf.astFormat(item, d)
53 }
54 }
55 }
56 if set(n.WhereClause) {
57 buf.WriteString(" WHERE ")
58 buf.astFormat(n.WhereClause, d)
59 }
60 }
61}

Callers

nothing calls this directly

Calls 2

setFunction · 0.85
astFormatMethod · 0.80

Tested by

no test coverage detected