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

Function tableConstraintSQL

pkg/formatter/render.go:1488–1519  ·  view source on GitHub ↗

tableConstraintSQL renders a table-level constraint.

(tc *ast.TableConstraint)

Source from the content-addressed store, hash-verified

1486
1487// tableConstraintSQL renders a table-level constraint.
1488func tableConstraintSQL(tc *ast.TableConstraint) string {
1489 var sb strings.Builder
1490 if tc.Name != "" {
1491 sb.WriteString("CONSTRAINT ")
1492 sb.WriteString(tc.Name)
1493 sb.WriteString(" ")
1494 }
1495 switch tc.Type {
1496 case "PRIMARY KEY":
1497 sb.WriteString("PRIMARY KEY (")
1498 sb.WriteString(strings.Join(tc.Columns, ", "))
1499 sb.WriteString(")")
1500 case "UNIQUE":
1501 sb.WriteString("UNIQUE (")
1502 sb.WriteString(strings.Join(tc.Columns, ", "))
1503 sb.WriteString(")")
1504 case "FOREIGN KEY":
1505 sb.WriteString("FOREIGN KEY (")
1506 sb.WriteString(strings.Join(tc.Columns, ", "))
1507 sb.WriteString(") ")
1508 if tc.References != nil {
1509 sb.WriteString(referenceSQL(tc.References))
1510 }
1511 case "CHECK":
1512 sb.WriteString("CHECK (")
1513 sb.WriteString(exprSQL(tc.Check))
1514 sb.WriteString(")")
1515 default:
1516 sb.WriteString(tc.Type)
1517 }
1518 return sb.String()
1519}
1520
1521// referenceSQL renders a REFERENCES clause.
1522func referenceSQL(r *ast.ReferenceDefinition) string {

Callers 2

renderCreateTableFunction · 0.70
renderAlterTableFunction · 0.70

Calls 3

referenceSQLFunction · 0.70
exprSQLFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected