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

Function renderCreateIndex

pkg/formatter/render.go:694–756  ·  view source on GitHub ↗
(c *ast.CreateIndexStatement, opts ast.FormatOptions)

Source from the content-addressed store, hash-verified

692}
693
694func renderCreateIndex(c *ast.CreateIndexStatement, opts ast.FormatOptions) string {
695 if c == nil {
696 return ""
697 }
698 f := newNodeFormatter(opts)
699 sb := f.sb
700
701 sb.WriteString(f.kw("CREATE"))
702 sb.WriteString(" ")
703 if c.Unique {
704 sb.WriteString(f.kw("UNIQUE"))
705 sb.WriteString(" ")
706 }
707 sb.WriteString(f.kw("INDEX"))
708 sb.WriteString(" ")
709 if c.IfNotExists {
710 sb.WriteString(f.kw("IF NOT EXISTS"))
711 sb.WriteString(" ")
712 }
713 sb.WriteString(c.Name)
714 sb.WriteString(" ")
715 sb.WriteString(f.kw("ON"))
716 sb.WriteString(" ")
717 sb.WriteString(c.Table)
718
719 if c.Using != "" {
720 sb.WriteString(" ")
721 sb.WriteString(f.kw("USING"))
722 sb.WriteString(" ")
723 sb.WriteString(c.Using)
724 }
725
726 sb.WriteString(" (")
727 cols := make([]string, len(c.Columns))
728 for i, col := range c.Columns {
729 s := col.Column
730 if col.Collate != "" {
731 s += " " + f.kw("COLLATE") + " " + col.Collate
732 }
733 if col.Direction != "" {
734 s += " " + f.kw(col.Direction)
735 }
736 if col.NullsLast {
737 s += " " + f.kw("NULLS LAST")
738 }
739 cols[i] = s
740 }
741 sb.WriteString(strings.Join(cols, ", "))
742 sb.WriteString(")")
743
744 if c.Where != nil {
745 sb.WriteString(f.clauseSep())
746 sb.WriteString(f.kw("WHERE"))
747 sb.WriteString(" ")
748 sb.WriteString(FormatExpression(c.Where, opts))
749 }
750
751 if opts.AddSemicolon {

Callers 1

FormatStatementFunction · 0.85

Calls 5

newNodeFormatterFunction · 0.85
FormatExpressionFunction · 0.85
kwMethod · 0.80
clauseSepMethod · 0.80
resultMethod · 0.80

Tested by

no test coverage detected