| 1656 | } |
| 1657 | |
| 1658 | func (node *ForeignKeyConstraintTableDef) doc(p *PrettyCfg) pretty.Doc { |
| 1659 | // Final layout: |
| 1660 | // [CONSTRAINT name] |
| 1661 | // FOREIGN KEY (...) |
| 1662 | // REFERENCES tbl (...) |
| 1663 | // [MATCH ...] |
| 1664 | // [ACTIONS ...] |
| 1665 | // |
| 1666 | // or (no constraint name): |
| 1667 | // |
| 1668 | // FOREIGN KEY (...) |
| 1669 | // REFERENCES tbl [(...)] |
| 1670 | // [MATCH ...] |
| 1671 | // [ACTIONS ...] |
| 1672 | // |
| 1673 | clauses := make([]pretty.Doc, 0, 4) |
| 1674 | title := pretty.ConcatSpace( |
| 1675 | pretty.Keyword("FOREIGN KEY"), |
| 1676 | p.bracket("(", p.Doc(&node.FromCols), ")")) |
| 1677 | |
| 1678 | if node.Name != "" { |
| 1679 | clauses = append(clauses, title) |
| 1680 | title = pretty.ConcatSpace(pretty.Keyword("CONSTRAINT"), p.Doc(&node.Name)) |
| 1681 | } |
| 1682 | |
| 1683 | ref := pretty.ConcatSpace( |
| 1684 | pretty.Keyword("REFERENCES"), p.Doc(&node.Table)) |
| 1685 | if len(node.ToCols) > 0 { |
| 1686 | ref = pretty.ConcatSpace(ref, p.bracket("(", p.Doc(&node.ToCols), ")")) |
| 1687 | } |
| 1688 | clauses = append(clauses, ref) |
| 1689 | |
| 1690 | if node.Match != MatchSimple { |
| 1691 | clauses = append(clauses, pretty.Keyword(node.Match.String())) |
| 1692 | } |
| 1693 | |
| 1694 | if actions := p.Doc(&node.Actions); ref != pretty.Nil { |
| 1695 | clauses = append(clauses, actions) |
| 1696 | } |
| 1697 | |
| 1698 | return p.nestUnder(title, pretty.Group(pretty.Stack(clauses...))) |
| 1699 | } |
| 1700 | |
| 1701 | func (p *PrettyCfg) maybePrependConstraintName(constraintName *Name, d pretty.Doc) pretty.Doc { |
| 1702 | if *constraintName != "" { |