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

Method SQL

pkg/sql/ast/sql.go:826–867  ·  view source on GitHub ↗

SQL returns the full SQL string for this CREATE INDEX statement including the UNIQUE modifier, IF NOT EXISTS, USING method, column list, and WHERE predicate.

()

Source from the content-addressed store, hash-verified

824// SQL returns the full SQL string for this CREATE INDEX statement including
825// the UNIQUE modifier, IF NOT EXISTS, USING method, column list, and WHERE predicate.
826func (c *CreateIndexStatement) SQL() string {
827 if c == nil {
828 return ""
829 }
830 sb := getBuilder()
831 defer putBuilder(sb)
832 sb.WriteString("CREATE ")
833 if c.Unique {
834 sb.WriteString("UNIQUE ")
835 }
836 sb.WriteString("INDEX ")
837 if c.IfNotExists {
838 sb.WriteString("IF NOT EXISTS ")
839 }
840 sb.WriteString(c.Name)
841 sb.WriteString(" ON ")
842 sb.WriteString(c.Table)
843
844 if c.Using != "" {
845 sb.WriteString(" USING ")
846 sb.WriteString(c.Using)
847 }
848
849 sb.WriteString(" (")
850 cols := make([]string, len(c.Columns))
851 for i, col := range c.Columns {
852 s := col.Column
853 if col.Direction != "" {
854 s += " " + col.Direction
855 }
856 cols[i] = s
857 }
858 sb.WriteString(strings.Join(cols, ", "))
859 sb.WriteString(")")
860
861 if c.Where != nil {
862 sb.WriteString(" WHERE ")
863 sb.WriteString(exprSQL(c.Where))
864 }
865
866 return sb.String()
867}
868
869// SQL returns the SQL representation of this ALTER TABLE statement.
870// Note: the parser returns AlterStatement (in alter.go); this method

Callers 2

TestNilSQLFunction · 0.95

Calls 4

getBuilderFunction · 0.85
putBuilderFunction · 0.85
exprSQLFunction · 0.70
StringMethod · 0.45

Tested by 2

TestNilSQLFunction · 0.76