RemoveSetClause returns a Rule that removes a column from the UPDATE SET clause. If the column is not found the statement is left unchanged (no error). The comparison is case-insensitive. Returns ErrUnsupportedStatement for non-UPDATE statements. Example: transform.Apply(stmt, transform.RemoveSe
(column string)
| 106 | // |
| 107 | // transform.Apply(stmt, transform.RemoveSetClause("internal_flag")) |
| 108 | func RemoveSetClause(column string) Rule { |
| 109 | return RuleFunc(func(stmt ast.Statement) error { |
| 110 | upd, ok := stmt.(*ast.UpdateStatement) |
| 111 | if !ok { |
| 112 | return &ErrUnsupportedStatement{Transform: "RemoveSetClause", Got: stmtTypeName(stmt)} |
| 113 | } |
| 114 | |
| 115 | filtered := upd.Assignments[:0] |
| 116 | for _, a := range upd.Assignments { |
| 117 | if !strings.EqualFold(identifierName(a.Column), column) { |
| 118 | filtered = append(filtered, a) |
| 119 | } |
| 120 | } |
| 121 | upd.Assignments = filtered |
| 122 | return nil |
| 123 | }) |
| 124 | } |
| 125 | |
| 126 | // ReplaceSetClause returns a Rule that completely replaces all SET assignments |
| 127 | // with the ones provided in the map. Keys are column names, values are SQL |