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:
@@ -10,6 +10,7 @@ package qb
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Order specifies sorting order.
|
// Order specifies sorting order.
|
||||||
@@ -53,9 +54,7 @@ func (b *SelectBuilder) ToCql() (stmt string, names []string) {
|
|||||||
cql.WriteString("DISTINCT ")
|
cql.WriteString("DISTINCT ")
|
||||||
b.distinct.writeCql(&cql)
|
b.distinct.writeCql(&cql)
|
||||||
case len(b.groupBy) > 0:
|
case len(b.groupBy) > 0:
|
||||||
b.groupBy.writeCql(&cql)
|
cql.WriteString(strings.Join(append(b.groupBy, b.columns...), ","))
|
||||||
cql.WriteByte(',')
|
|
||||||
b.columns.writeCql(&cql)
|
|
||||||
case len(b.columns) == 0:
|
case len(b.columns) == 0:
|
||||||
cql.WriteByte('*')
|
cql.WriteByte('*')
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package qb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// placeholders returns a string with count ? placeholders joined with commas.
|
// placeholders returns a string with count ? placeholders joined with commas.
|
||||||
@@ -24,10 +25,5 @@ func placeholders(cql *bytes.Buffer, count int) {
|
|||||||
type columns []string
|
type columns []string
|
||||||
|
|
||||||
func (cols columns) writeCql(cql *bytes.Buffer) {
|
func (cols columns) writeCql(cql *bytes.Buffer) {
|
||||||
for i, c := range cols {
|
cql.WriteString(strings.Join(cols, ","))
|
||||||
cql.WriteString(c)
|
|
||||||
if i < len(cols)-1 {
|
|
||||||
cql.WriteByte(',')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user