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

@@ -24,6 +24,7 @@ type InsertBuilder struct {
columns []initializer
unique bool
using using
json bool
}
// Insert returns a new InsertBuilder with the given table name.
@@ -43,6 +44,13 @@ func (b *InsertBuilder) ToCql() (stmt string, names []string) {
cql.WriteString(b.table)
cql.WriteByte(' ')
if b.json {
// Ignore everything else since it goes into the Json
cql.WriteString("JSON ?")
stmt = cql.String()
return
}
cql.WriteByte('(')
for i, c := range b.columns {
cql.WriteString(c.column)
@@ -76,6 +84,12 @@ func (b *InsertBuilder) Into(table string) *InsertBuilder {
return b
}
// Json sets the Json clause of the query.
func (b *InsertBuilder) Json() *InsertBuilder {
b.json = true
return b
}
// Columns adds insert columns to the query.
func (b *InsertBuilder) Columns(columns ...string) *InsertBuilder {
for _, c := range columns {