qb: json support

This commit is contained in:
Henrik Johansson
2019-05-13 14:01:13 +02:00
committed by Michal Matczuk
parent eadf9b5427
commit 31ae81aba6
5 changed files with 43 additions and 0 deletions

View File

@@ -40,6 +40,7 @@ type SelectBuilder struct {
limit uint
limitPerPartition uint
allowFiltering bool
json bool
}
// Select returns a new SelectBuilder with the given table name.
@@ -54,6 +55,11 @@ func (b *SelectBuilder) ToCql() (stmt string, names []string) {
cql := bytes.Buffer{}
cql.WriteString("SELECT ")
if b.json {
cql.WriteString("JSON ")
}
switch {
case len(b.distinct) > 0:
cql.WriteString("DISTINCT ")
@@ -113,6 +119,12 @@ func (b *SelectBuilder) From(table string) *SelectBuilder {
return b
}
// Json sets the clause of the query.
func (b *SelectBuilder) Json() *SelectBuilder {
b.json = true
return b
}
// Columns adds result columns to the query.
func (b *SelectBuilder) Columns(columns ...string) *SelectBuilder {
b.columns = append(b.columns, columns...)