(p *PrettyCfg)
| 1713 | } |
| 1714 | |
| 1715 | func (node *ColumnTableDef) docRow(p *PrettyCfg) pretty.TableRow { |
| 1716 | // Final layout: |
| 1717 | // colname |
| 1718 | // type |
| 1719 | // [AS ( ... ) STORED] |
| 1720 | // [[CREATE [IF NOT EXISTS]] FAMILY [name]] |
| 1721 | // [[CONSTRAINT name] DEFAULT expr] |
| 1722 | // [[CONSTRAINT name] {NULL|NOT NULL}] |
| 1723 | // [[CONSTRAINT name] {PRIMARY KEY|UNIQUE}] |
| 1724 | // [[CONSTRAINT name] CHECK ...] |
| 1725 | // [[CONSTRAINT name] REFERENCES tbl (...) |
| 1726 | // [MATCH ...] |
| 1727 | // [ACTIONS ...] |
| 1728 | // ] |
| 1729 | // |
| 1730 | clauses := make([]pretty.Doc, 0, 7) |
| 1731 | |
| 1732 | // Column type. |
| 1733 | // ColumnTableDef node type will not be specified if it represents a CREATE |
| 1734 | // TABLE ... AS query. |
| 1735 | if node.Type != nil { |
| 1736 | clauses = append(clauses, pretty.Text(node.columnTypeString())) |
| 1737 | } |
| 1738 | |
| 1739 | // Compute expression (for computed columns). |
| 1740 | if node.IsComputed() { |
| 1741 | clauses = append(clauses, pretty.ConcatSpace(pretty.Keyword("AS"), |
| 1742 | p.bracket("(", p.Doc(node.Computed.Expr), ") STORED"), |
| 1743 | )) |
| 1744 | } |
| 1745 | |
| 1746 | // Column family. |
| 1747 | if node.HasColumnFamily() { |
| 1748 | d := pretty.Keyword("FAMILY") |
| 1749 | if node.Family.Name != "" { |
| 1750 | d = pretty.ConcatSpace(d, p.Doc(&node.Family.Name)) |
| 1751 | } |
| 1752 | if node.Family.Create { |
| 1753 | c := pretty.Keyword("CREATE") |
| 1754 | if node.Family.IfNotExists { |
| 1755 | c = pretty.ConcatSpace(c, pretty.Keyword("IF NOT EXISTS")) |
| 1756 | } |
| 1757 | d = pretty.ConcatSpace(c, d) |
| 1758 | } |
| 1759 | clauses = append(clauses, d) |
| 1760 | } |
| 1761 | |
| 1762 | // DEFAULT constraint. |
| 1763 | if node.HasDefaultExpr() { |
| 1764 | clauses = append(clauses, p.maybePrependConstraintName(&node.DefaultExpr.ConstraintName, |
| 1765 | pretty.ConcatSpace(pretty.Keyword("DEFAULT"), p.Doc(node.DefaultExpr.Expr)))) |
| 1766 | } |
| 1767 | |
| 1768 | // NULL/NOT NULL constraint. |
| 1769 | nConstraint := pretty.Nil |
| 1770 | switch node.Nullable.Nullability { |
| 1771 | case Null: |
| 1772 | nConstraint = pretty.Keyword("NULL") |
no test coverage detected