fix(qb): Fixed group by generation

* In qb/select.go, if there are no colums and the query have a GroupBy
statement then the query will be malformated.
* In qb/utils.go, refactor writeCql with a strings.Join call.
This commit is contained in:
sagarafr
2018-10-24 14:27:03 +02:00
committed by Michal Matczuk
parent 8ea6a9d5f5
commit 19dedfc6a0
2 changed files with 4 additions and 9 deletions

View File

@@ -10,6 +10,7 @@ package qb
import (
"bytes"
"fmt"
"strings"
)
// Order specifies sorting order.
@@ -53,9 +54,7 @@ func (b *SelectBuilder) ToCql() (stmt string, names []string) {
cql.WriteString("DISTINCT ")
b.distinct.writeCql(&cql)
case len(b.groupBy) > 0:
b.groupBy.writeCql(&cql)
cql.WriteByte(',')
b.columns.writeCql(&cql)
cql.WriteString(strings.Join(append(b.groupBy, b.columns...), ","))
case len(b.columns) == 0:
cql.WriteByte('*')
default: