| 18 | } |
| 19 | |
| 20 | func (n *JoinExpr) Format(buf *TrackedBuffer, d format.Dialect) { |
| 21 | if n == nil { |
| 22 | return |
| 23 | } |
| 24 | buf.astFormat(n.Larg, d) |
| 25 | if n.IsNatural { |
| 26 | buf.WriteString(" NATURAL") |
| 27 | } |
| 28 | switch n.Jointype { |
| 29 | case JoinTypeLeft: |
| 30 | buf.WriteString(" LEFT JOIN ") |
| 31 | case JoinTypeRight: |
| 32 | buf.WriteString(" RIGHT JOIN ") |
| 33 | case JoinTypeFull: |
| 34 | buf.WriteString(" FULL JOIN ") |
| 35 | case JoinTypeInner: |
| 36 | // CROSS JOIN has no ON or USING clause |
| 37 | if !items(n.UsingClause) && !set(n.Quals) { |
| 38 | buf.WriteString(" CROSS JOIN ") |
| 39 | } else { |
| 40 | buf.WriteString(" JOIN ") |
| 41 | } |
| 42 | default: |
| 43 | buf.WriteString(" JOIN ") |
| 44 | } |
| 45 | buf.astFormat(n.Rarg, d) |
| 46 | if items(n.UsingClause) { |
| 47 | buf.WriteString(" USING (") |
| 48 | buf.join(n.UsingClause, d, ", ") |
| 49 | buf.WriteString(")") |
| 50 | } else if set(n.Quals) { |
| 51 | buf.WriteString(" ON ") |
| 52 | buf.astFormat(n.Quals, d) |
| 53 | } |
| 54 | } |