Format implements the NodeFormatter interface.
(ctx *FmtCtx)
| 45 | |
| 46 | // Format implements the NodeFormatter interface. |
| 47 | func (node *Insert) Format(ctx *FmtCtx) { |
| 48 | ctx.FormatNode(node.With) |
| 49 | if node.OnConflict.IsUpsertAlias() { |
| 50 | ctx.WriteString("UPSERT") |
| 51 | } else { |
| 52 | ctx.WriteString("INSERT") |
| 53 | } |
| 54 | ctx.WriteString(" INTO ") |
| 55 | ctx.FormatNode(node.Table) |
| 56 | if node.Columns != nil { |
| 57 | ctx.WriteByte('(') |
| 58 | ctx.FormatNode(&node.Columns) |
| 59 | ctx.WriteByte(')') |
| 60 | } |
| 61 | if node.DefaultValues() { |
| 62 | ctx.WriteString(" DEFAULT VALUES") |
| 63 | } else { |
| 64 | ctx.WriteByte(' ') |
| 65 | ctx.FormatNode(node.Rows) |
| 66 | } |
| 67 | if node.OnConflict != nil && !node.OnConflict.IsUpsertAlias() { |
| 68 | ctx.WriteString(" ON CONFLICT") |
| 69 | if len(node.OnConflict.Columns) > 0 { |
| 70 | ctx.WriteString(" (") |
| 71 | ctx.FormatNode(&node.OnConflict.Columns) |
| 72 | ctx.WriteString(")") |
| 73 | } |
| 74 | if node.OnConflict.ArbiterPredicate != nil { |
| 75 | ctx.WriteString(" WHERE ") |
| 76 | ctx.FormatNode(node.OnConflict.ArbiterPredicate) |
| 77 | } |
| 78 | if node.OnConflict.DoNothing { |
| 79 | ctx.WriteString(" DO NOTHING") |
| 80 | } else { |
| 81 | ctx.WriteString(" DO UPDATE SET ") |
| 82 | ctx.FormatNode(&node.OnConflict.Exprs) |
| 83 | if node.OnConflict.Where != nil { |
| 84 | ctx.WriteByte(' ') |
| 85 | ctx.FormatNode(node.OnConflict.Where) |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | if HasReturningClause(node.Returning) { |
| 90 | ctx.WriteByte(' ') |
| 91 | ctx.FormatNode(node.Returning) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // DefaultValues returns true iff only default values are being inserted. |
| 96 | func (node *Insert) DefaultValues() bool { |
nothing calls this directly
no test coverage detected