formatAlterTableOperation formats a single ALTER TABLE operation
(op *ast.AlterTableOperation)
| 496 | |
| 497 | // formatAlterTableOperation formats a single ALTER TABLE operation |
| 498 | func (f *SQLFormatter) formatAlterTableOperation(op *ast.AlterTableOperation) { |
| 499 | switch op.Type { |
| 500 | case ast.AddColumn: |
| 501 | f.writeKeyword("ADD") |
| 502 | if op.ColumnKeyword { |
| 503 | f.builder.WriteString(" ") |
| 504 | f.writeKeyword("COLUMN") |
| 505 | } |
| 506 | if op.ColumnDef != nil { |
| 507 | f.builder.WriteString(" " + op.ColumnDef.Name) |
| 508 | if op.ColumnDef.Type != "" { |
| 509 | f.builder.WriteString(" " + op.ColumnDef.Type) |
| 510 | } |
| 511 | } |
| 512 | case ast.DropColumn: |
| 513 | f.writeKeyword("DROP") |
| 514 | if op.ColumnKeyword { |
| 515 | f.builder.WriteString(" ") |
| 516 | f.writeKeyword("COLUMN") |
| 517 | } |
| 518 | if op.ColumnDef != nil { |
| 519 | f.builder.WriteString(" " + op.ColumnDef.Name) |
| 520 | } |
| 521 | case ast.AddConstraint: |
| 522 | f.writeKeyword("ADD CONSTRAINT") |
| 523 | if op.Constraint != nil && op.Constraint.Name != "" { |
| 524 | f.builder.WriteString(" " + op.Constraint.Name) |
| 525 | } |
| 526 | case ast.DropConstraint: |
| 527 | f.writeKeyword("DROP CONSTRAINT") |
| 528 | if op.ConstraintName != nil { |
| 529 | f.builder.WriteString(" " + op.ConstraintName.String()) |
| 530 | } |
| 531 | case ast.RenameColumn: |
| 532 | f.writeKeyword("RENAME COLUMN") |
| 533 | if op.OldColumnName != nil { |
| 534 | f.builder.WriteString(" " + op.OldColumnName.String()) |
| 535 | } |
| 536 | f.builder.WriteString(" ") |
| 537 | f.writeKeyword("TO") |
| 538 | if op.NewColumnName != nil { |
| 539 | f.builder.WriteString(" " + op.NewColumnName.String()) |
| 540 | } |
| 541 | default: |
| 542 | // Fallback for unsupported operations |
| 543 | f.builder.WriteString("...") |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | // formatWithClause formats WITH (CTE) clauses |
| 548 | func (f *SQLFormatter) formatWithClause(with *ast.WithClause) error { |
no test coverage detected