diff --git a/clause/select.go b/clause/select.go index b93b8769..d8e9f801 100644 --- a/clause/select.go +++ b/clause/select.go @@ -43,3 +43,17 @@ func (s Select) MergeClause(clause *Clause) { clause.Expression = s } } + +// CommaExpression represents a group of expressions separated by commas. +type CommaExpression struct { + Exprs []Expression +} + +func (comma CommaExpression) Build(builder Builder) { + for idx, expr := range comma.Exprs { + if idx > 0 { + _, _ = builder.WriteString(", ") + } + expr.Build(builder) + } +} diff --git a/clause/select_test.go b/clause/select_test.go index b7296434..9fce0783 100644 --- a/clause/select_test.go +++ b/clause/select_test.go @@ -31,6 +31,18 @@ func TestSelect(t *testing.T) { }, clause.From{}}, "SELECT `name` FROM `users`", nil, }, + { + []clause.Interface{clause.Select{ + Expression: clause.CommaExpression{ + Exprs: []clause.Expression{ + clause.NamedExpr{"?", []interface{}{clause.Column{Name: "id"}}}, + clause.NamedExpr{"?", []interface{}{clause.Column{Name: "name"}}}, + clause.NamedExpr{"LENGTH(?)", []interface{}{clause.Column{Name: "mobile"}}}, + }, + }, + }, clause.From{}}, + "SELECT `id`, `name`, LENGTH(`mobile`) FROM `users`", nil, + }, } for idx, result := range results {