MCPcopy
hub / github.com/sqldef/sqldef / Format

Method Format

parser/node.go:738–779  ·  view source on GitHub ↗

Format formats the node.

(buf *nodeBuffer)

Source from the content-addressed store, hash-verified

736
737// Format formats the node.
738func (ts *TableSpec) Format(buf *nodeBuffer) {
739 buf.Printf("(\n")
740 for i, col := range ts.Columns {
741 if i == 0 {
742 buf.Printf("\t%v", col)
743 } else {
744 buf.Printf(",\n\t%v", col)
745 }
746 }
747 for _, idx := range ts.Indexes {
748 buf.Printf(",\n\t%v", idx)
749 }
750 for _, ck := range ts.Checks {
751 buf.Printf(",\n\t%v", ck)
752 }
753 for _, fk := range ts.ForeignKeys {
754 buf.Printf(",\n\t%v", fk)
755 }
756 for _, ex := range ts.Exclusions {
757 buf.Printf(",\n\t%v", ex)
758 }
759
760 var kvOptions strings.Builder
761 var sqliteOpts []string
762 for key, value := range ts.Options {
763 if value == "" {
764 sqliteOpts = append(sqliteOpts, key)
765 } else {
766 kvOptions.WriteString(" " + key + "=" + value)
767 }
768 }
769 if len(sqliteOpts) > 0 {
770 sort.Strings(sqliteOpts)
771 buf.Printf("\n) %s", strings.Join(sqliteOpts, ", "))
772 } else {
773 buf.Printf("\n)%s", strings.ReplaceAll(kvOptions.String(), ", ", ",\n "))
774 }
775 if ts.Partition != nil {
776 buf.Printf("\n")
777 ts.Partition.Format(buf)
778 }
779}
780
781// addColumn appends the given column to the list in the spec
782func (ts *TableSpec) addColumn(cd *ColumnDefinition) {

Callers

nothing calls this directly

Calls 3

PrintfMethod · 0.65
FormatMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected