qb: insert

This commit is contained in:
Michał Matczuk
2017-07-26 13:57:10 +02:00
parent 7b5d550b50
commit 5db5de8822
5 changed files with 214 additions and 3 deletions

36
qb/expr.go Normal file
View File

@@ -0,0 +1,36 @@
package qb
import (
"bytes"
"fmt"
"strings"
"time"
)
type expr interface {
// WriteCql writes a CQL representation of the expr to a buffer and returns
// slice of parameter names.
WriteCql(cql *bytes.Buffer) (names []string)
}
type using struct {
timestamp time.Time
ttl time.Duration
}
func (u using) WriteCql(cql *bytes.Buffer) (names []string) {
var v []string
if !u.timestamp.IsZero() {
v = append(v, fmt.Sprint("TIMESTAMP ", u.timestamp.UnixNano()/1000))
}
if u.ttl != 0 {
v = append(v, fmt.Sprint("TTL ", int(u.ttl.Seconds())))
}
if len(v) > 0 {
cql.WriteString("USING ")
cql.WriteString(strings.Join(v, ","))
cql.WriteString(" ")
}
return
}