columnConstraintSQL renders a column constraint.
(c *ast.ColumnConstraint)
| 1464 | |
| 1465 | // columnConstraintSQL renders a column constraint. |
| 1466 | func columnConstraintSQL(c *ast.ColumnConstraint) string { |
| 1467 | switch c.Type { |
| 1468 | case "NOT NULL", "UNIQUE", "PRIMARY KEY": |
| 1469 | return c.Type |
| 1470 | case "DEFAULT": |
| 1471 | return "DEFAULT " + exprSQL(c.Default) |
| 1472 | case "REFERENCES": |
| 1473 | if c.References != nil { |
| 1474 | return referenceSQL(c.References) |
| 1475 | } |
| 1476 | return "REFERENCES" |
| 1477 | case "CHECK": |
| 1478 | return "CHECK (" + exprSQL(c.Check) + ")" |
| 1479 | default: |
| 1480 | if c.AutoIncrement { |
| 1481 | return "AUTO_INCREMENT" |
| 1482 | } |
| 1483 | return c.Type |
| 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | // tableConstraintSQL renders a table-level constraint. |
| 1488 | func tableConstraintSQL(tc *ast.TableConstraint) string { |
no test coverage detected