MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / formatMergeWhenClause

Method formatMergeWhenClause

cmd/gosqlx/cmd/sql_formatter.go:1309–1348  ·  view source on GitHub ↗

formatMergeWhenClause formats a WHEN clause in a MERGE statement

(when *ast.MergeWhenClause)

Source from the content-addressed store, hash-verified

1307
1308// formatMergeWhenClause formats a WHEN clause in a MERGE statement
1309func (f *SQLFormatter) formatMergeWhenClause(when *ast.MergeWhenClause) error {
1310 f.writeNewline()
1311 f.writeKeyword("WHEN")
1312 f.builder.WriteString(" ")
1313
1314 // Format the match type
1315 switch when.Type {
1316 case "MATCHED":
1317 f.writeKeyword("MATCHED")
1318 case "NOT_MATCHED":
1319 f.writeKeyword("NOT MATCHED")
1320 case "NOT_MATCHED_BY_SOURCE":
1321 f.writeKeyword("NOT MATCHED BY SOURCE")
1322 default:
1323 f.writeKeyword(when.Type)
1324 }
1325
1326 // Format optional AND condition
1327 if when.Condition != nil {
1328 f.builder.WriteString(" ")
1329 f.writeKeyword("AND")
1330 f.builder.WriteString(" ")
1331 if err := f.formatExpression(when.Condition); err != nil {
1332 return fmt.Errorf("failed to format WHEN condition: %w", err)
1333 }
1334 }
1335
1336 // Format THEN action
1337 f.builder.WriteString(" ")
1338 f.writeKeyword("THEN")
1339 f.writeNewline()
1340 f.increaseIndent()
1341 f.builder.WriteString(f.currentIndent())
1342 if err := f.formatMergeAction(when.Action); err != nil {
1343 return fmt.Errorf("failed to format MERGE action: %w", err)
1344 }
1345 f.decreaseIndent()
1346
1347 return nil
1348}
1349
1350// formatMergeAction formats the action part of a WHEN clause (UPDATE/INSERT/DELETE)
1351func (f *SQLFormatter) formatMergeAction(action *ast.MergeAction) error {

Callers 1

formatMergeStatementMethod · 0.95

Calls 8

writeNewlineMethod · 0.95
writeKeywordMethod · 0.95
formatExpressionMethod · 0.95
increaseIndentMethod · 0.95
currentIndentMethod · 0.95
formatMergeActionMethod · 0.95
decreaseIndentMethod · 0.95
ErrorfMethod · 0.65

Tested by

no test coverage detected