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

Method formatAlterStatement

cmd/gosqlx/cmd/sql_formatter.go:460–495  ·  view source on GitHub ↗

formatAlterStatement formats the generic ALTER statement (from alter.go)

(stmt *ast.AlterStatement)

Source from the content-addressed store, hash-verified

458
459// formatAlterStatement formats the generic ALTER statement (from alter.go)
460func (f *SQLFormatter) formatAlterStatement(stmt *ast.AlterStatement) error {
461 // Format ALTER TABLE if it's a table alteration
462 if stmt.Type == ast.AlterTypeTable {
463 f.writeKeyword("ALTER TABLE")
464 f.builder.WriteString(" " + stmt.Name)
465
466 // Format the operation if present
467 if stmt.Operation != nil {
468 if op, ok := stmt.Operation.(*ast.AlterTableOperation); ok {
469 f.writeNewline()
470 f.increaseIndent()
471 f.builder.WriteString(f.currentIndent())
472 f.formatAlterTableOperation(op)
473 f.decreaseIndent()
474 }
475 }
476 return nil
477 }
478
479 // For other ALTER types, provide a basic format
480 f.writeKeyword("ALTER")
481 switch stmt.Type {
482 case ast.AlterTypeRole:
483 f.builder.WriteString(" ")
484 f.writeKeyword("ROLE")
485 case ast.AlterTypePolicy:
486 f.builder.WriteString(" ")
487 f.writeKeyword("POLICY")
488 case ast.AlterTypeConnector:
489 f.builder.WriteString(" ")
490 f.writeKeyword("CONNECTOR")
491 }
492 f.builder.WriteString(" " + stmt.Name)
493
494 return nil
495}
496
497// formatAlterTableOperation formats a single ALTER TABLE operation
498func (f *SQLFormatter) formatAlterTableOperation(op *ast.AlterTableOperation) {

Callers 1

formatStatementMethod · 0.95

Calls 6

writeKeywordMethod · 0.95
writeNewlineMethod · 0.95
increaseIndentMethod · 0.95
currentIndentMethod · 0.95
decreaseIndentMethod · 0.95

Tested by

no test coverage detected