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

Method formatWithClause

cmd/gosqlx/cmd/sql_formatter.go:548–594  ·  view source on GitHub ↗

formatWithClause formats WITH (CTE) clauses

(with *ast.WithClause)

Source from the content-addressed store, hash-verified

546
547// formatWithClause formats WITH (CTE) clauses
548func (f *SQLFormatter) formatWithClause(with *ast.WithClause) error {
549 f.writeKeyword("WITH")
550 if with.Recursive {
551 f.builder.WriteString(" ")
552 f.writeKeyword("RECURSIVE")
553 }
554 f.builder.WriteString(" ")
555
556 for i, cte := range with.CTEs {
557 if i > 0 {
558 f.builder.WriteString(", ")
559 }
560 f.builder.WriteString(cte.Name)
561
562 if len(cte.Columns) > 0 {
563 f.builder.WriteString(" (")
564 for j, col := range cte.Columns {
565 if j > 0 {
566 f.builder.WriteString(", ")
567 }
568 f.builder.WriteString(col)
569 }
570 f.builder.WriteString(")")
571 }
572
573 f.builder.WriteString(" ")
574 f.writeKeyword("AS")
575 f.builder.WriteString(" (")
576
577 if !f.compact {
578 f.writeNewline()
579 f.increaseIndent()
580 }
581
582 if err := f.formatStatement(cte.Statement); err != nil {
583 return err
584 }
585
586 if !f.compact {
587 f.decreaseIndent()
588 f.writeNewline()
589 }
590 f.builder.WriteString(")")
591 }
592
593 return nil
594}
595
596// formatJoin formats JOIN clauses
597func (f *SQLFormatter) formatJoin(join *ast.JoinClause) error {

Callers 1

formatSelectMethod · 0.95

Calls 5

writeKeywordMethod · 0.95
writeNewlineMethod · 0.95
increaseIndentMethod · 0.95
formatStatementMethod · 0.95
decreaseIndentMethod · 0.95

Tested by

no test coverage detected