(buf *strings.Builder, n *ast.DeleteStmt, sql string)
| 235 | } |
| 236 | |
| 237 | func writeDeleteSuffix(buf *strings.Builder, n *ast.DeleteStmt, sql string) error { |
| 238 | if n.Relation == nil { |
| 239 | return nil |
| 240 | } |
| 241 | |
| 242 | relText := extractNodeText(n.Relation.Loc, sql) |
| 243 | if _, err := fmt.Fprintf(buf, "FROM %s", relText); err != nil { |
| 244 | return errors.Wrap(err, "failed to write to buffer") |
| 245 | } |
| 246 | |
| 247 | if n.UsingClause != nil && n.UsingClause.Len() > 0 { |
| 248 | usingText := extractNodeText(ast.ListSpan(n.UsingClause), sql) |
| 249 | if usingText != "" { |
| 250 | if _, err := fmt.Fprintf(buf, ", %s", usingText); err != nil { |
| 251 | return errors.Wrap(err, "failed to write to buffer") |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | if n.WhereClause != nil { |
| 257 | whereText := extractNodeText(ast.NodeLoc(n.WhereClause), sql) |
| 258 | if whereText != "" { |
| 259 | if _, err := fmt.Fprintf(buf, " WHERE %s", whereText); err != nil { |
| 260 | return errors.Wrap(err, "failed to write to buffer") |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | return nil |
| 265 | } |
| 266 | |
| 267 | // extractNodeText extracts trimmed text from SQL using a Loc range. |
| 268 | func extractNodeText(loc ast.Loc, sql string) string { |
no test coverage detected