package clause

// Select select attrs when querying, updating, creating
type Select struct {
	Distinct   bool
	Columns    []Column
	Expression Expression
}

func ( Select) () string {
	return "SELECT"
}

func ( Select) ( Builder) {
	if len(.Columns) > 0 {
		if .Distinct {
			.WriteString("DISTINCT ")
		}

		for ,  := range .Columns {
			if  > 0 {
				.WriteByte(',')
			}
			.WriteQuoted()
		}
	} else {
		.WriteByte('*')
	}
}

func ( Select) ( *Clause) {
	if .Expression != nil {
		if .Distinct {
			if ,  := .Expression.(Expr);  {
				.SQL = "DISTINCT " + .SQL
				.Expression = 
				return
			}
		}

		.Expression = .Expression
	} else {
		.Expression = 
	}
}

// CommaExpression represents a group of expressions separated by commas.
type CommaExpression struct {
	Exprs []Expression
}

func ( CommaExpression) ( Builder) {
	for ,  := range .Exprs {
		if  > 0 {
			_, _ = .WriteString(", ")
		}
		.Build()
	}
}