Format implements the NodeFormatter interface.
(ctx *FmtCtx)
| 439 | |
| 440 | // Format implements the NodeFormatter interface. |
| 441 | func (node *ColumnTableDef) Format(ctx *FmtCtx) { |
| 442 | ctx.FormatNode(&node.Name) |
| 443 | |
| 444 | // ColumnTableDef node type will not be specified if it represents a CREATE |
| 445 | // TABLE ... AS query. |
| 446 | if node.Type != nil { |
| 447 | ctx.WriteByte(' ') |
| 448 | ctx.WriteString(node.columnTypeString()) |
| 449 | } |
| 450 | |
| 451 | if node.Nullable.Nullability != SilentNull && node.Nullable.ConstraintName != "" { |
| 452 | ctx.WriteString(" CONSTRAINT ") |
| 453 | ctx.FormatNode(&node.Nullable.ConstraintName) |
| 454 | } |
| 455 | switch node.Nullable.Nullability { |
| 456 | case Null: |
| 457 | ctx.WriteString(" NULL") |
| 458 | case NotNull: |
| 459 | ctx.WriteString(" NOT NULL") |
| 460 | default: |
| 461 | } |
| 462 | for _, checkExpr := range node.CheckExprs { |
| 463 | if checkExpr.ConstraintName != "" { |
| 464 | ctx.WriteString(" CONSTRAINT ") |
| 465 | ctx.FormatNode(&checkExpr.ConstraintName) |
| 466 | } |
| 467 | ctx.WriteString(" CHECK (") |
| 468 | ctx.FormatNode(checkExpr.Expr) |
| 469 | ctx.WriteByte(')') |
| 470 | if checkExpr.NoInherit { |
| 471 | ctx.WriteString(" NO INHERIT") |
| 472 | } |
| 473 | } |
| 474 | if node.HasDefaultExpr() { |
| 475 | if node.DefaultExpr.ConstraintName != "" { |
| 476 | ctx.WriteString(" CONSTRAINT ") |
| 477 | ctx.FormatNode(&node.DefaultExpr.ConstraintName) |
| 478 | } |
| 479 | ctx.WriteString(" DEFAULT ") |
| 480 | ctx.FormatNode(node.DefaultExpr.Expr) |
| 481 | } |
| 482 | if node.IsComputed() { |
| 483 | ctx.WriteString(" GENERATED") |
| 484 | if node.Computed.ByDefault { |
| 485 | ctx.WriteString(" BY DEFAULT") |
| 486 | } else { |
| 487 | ctx.WriteString(" ALWAYS") |
| 488 | } |
| 489 | ctx.WriteString(" AS") |
| 490 | if node.Computed.Expr != nil { |
| 491 | ctx.WriteString(" ( ") |
| 492 | ctx.FormatNode(node.Computed.Expr) |
| 493 | ctx.WriteString(" ) STORED") |
| 494 | } else { |
| 495 | ctx.WriteString(" IDENTITY") |
| 496 | if node.Computed.Options != nil { |
| 497 | ctx.WriteString(" ( ") |
| 498 | ctx.FormatNode(&node.Computed.Options) |
nothing calls this directly
no test coverage detected