This commit is contained in:
Michał Matczuk
2017-07-28 10:18:38 +02:00
parent 3b3c7087d2
commit 41bb8def2a
12 changed files with 247 additions and 132 deletions

View File

@@ -1,13 +1,14 @@
package qb
// INSERT reference:
// http://docs.datastax.com/en/dse/5.1/cql/cql/cql_reference/cql_commands/cqlInsert.html
// https://cassandra.apache.org/doc/latest/cql/dml.html#insert
import (
"bytes"
"time"
)
// InsertBuilder builds CQL INSERT statements.
type InsertBuilder struct {
table string
columns columns
@@ -22,6 +23,7 @@ func Insert(table string) *InsertBuilder {
}
}
// ToCql builds the query into a CQL string and named args.
func (b *InsertBuilder) ToCql() (stmt string, names []string) {
cql := bytes.Buffer{}
@@ -49,26 +51,31 @@ func (b *InsertBuilder) ToCql() (stmt string, names []string) {
return
}
// Into sets the INTO clause of the query.
func (b *InsertBuilder) Into(table string) *InsertBuilder {
b.table = table
return b
}
// Columns adds insert columns to the query.
func (b *InsertBuilder) Columns(columns ...string) *InsertBuilder {
b.columns = append(b.columns, columns...)
return b
}
// Unique sets a IF NOT EXISTS clause on the query.
func (b *InsertBuilder) Unique() *InsertBuilder {
b.unique = true
return b
}
// Timestamp sets a USING TIMESTAMP clause on the query.
func (b *InsertBuilder) Timestamp(t time.Time) *InsertBuilder {
b.using.timestamp = t
return b
}
// TTL sets a USING TTL clause on the query.
func (b *InsertBuilder) TTL(d time.Duration) *InsertBuilder {
b.using.ttl = d
return b