package clause

type JoinType string

const (
	CrossJoin JoinType = "CROSS"
	InnerJoin JoinType = "INNER"
	LeftJoin  JoinType = "LEFT"
	RightJoin JoinType = "RIGHT"
)

// Join clause for from
type Join struct {
	Type       JoinType
	Table      Table
	ON         Where
	Using      []string
	Expression Expression
}

func ( Join) ( Builder) {
	if .Expression != nil {
		.Expression.Build()
	} else {
		if .Type != "" {
			.WriteString(string(.Type))
			.WriteByte(' ')
		}

		.WriteString("JOIN ")
		.WriteQuoted(.Table)

		if len(.ON.Exprs) > 0 {
			.WriteString(" ON ")
			.ON.Build()
		} else if len(.Using) > 0 {
			.WriteString(" USING (")
			for ,  := range .Using {
				if  > 0 {
					.WriteByte(',')
				}
				.WriteQuoted()
			}
			.WriteByte(')')
		}
	}
}