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

Method Format

internal/sql/ast/update_stmt.go:23–122  ·  view source on GitHub ↗
(buf *TrackedBuffer, d format.Dialect)

Source from the content-addressed store, hash-verified

21}
22
23func (n *UpdateStmt) Format(buf *TrackedBuffer, d format.Dialect) {
24 if n == nil {
25 return
26 }
27 if n.WithClause != nil {
28 buf.astFormat(n.WithClause, d)
29 buf.WriteString(" ")
30 }
31
32 buf.WriteString("UPDATE ")
33 if items(n.Relations) {
34 buf.astFormat(n.Relations, d)
35 }
36
37 if items(n.TargetList) {
38 buf.WriteString(" SET ")
39
40 multi := false
41 for _, item := range n.TargetList.Items {
42 switch nn := item.(type) {
43 case *ResTarget:
44 if _, ok := nn.Val.(*MultiAssignRef); ok {
45 multi = true
46 }
47 }
48 }
49 if multi {
50 names := []string{}
51 vals := &List{}
52 for _, item := range n.TargetList.Items {
53 res, ok := item.(*ResTarget)
54 if !ok {
55 continue
56 }
57 if res.Name != nil {
58 names = append(names, *res.Name)
59 }
60 multi, ok := res.Val.(*MultiAssignRef)
61 if !ok {
62 vals.Items = append(vals.Items, res.Val)
63 continue
64 }
65 row, ok := multi.Source.(*RowExpr)
66 if !ok {
67 vals.Items = append(vals.Items, res.Val)
68 continue
69 }
70 vals.Items = append(vals.Items, row.Args.Items[multi.Colno-1])
71 }
72
73 buf.WriteString("(")
74 buf.WriteString(strings.Join(names, ","))
75 buf.WriteString(") = (")
76 buf.join(vals, d, ",")
77 buf.WriteString(")")
78 } else {
79 for i, item := range n.TargetList.Items {
80 if i > 0 {

Callers

nothing calls this directly

Calls 6

itemsFunction · 0.85
setFunction · 0.85
astFormatMethod · 0.80
joinMethod · 0.80
QuoteIdentMethod · 0.65
JoinMethod · 0.45

Tested by

no test coverage detected