2017-07-26 13:57:10 +02:00
|
|
|
package qb
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
)
|
|
|
|
|
|
2017-07-27 09:48:33 +02:00
|
|
|
type columns []string
|
|
|
|
|
|
2017-07-27 12:28:01 +02:00
|
|
|
func (cols columns) writeCql(cql *bytes.Buffer) {
|
2017-07-27 09:48:33 +02:00
|
|
|
for i, c := range cols {
|
|
|
|
|
cql.WriteString(c)
|
|
|
|
|
if i < len(cols)-1 {
|
|
|
|
|
cql.WriteByte(',')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-26 13:57:10 +02:00
|
|
|
type using struct {
|
2017-08-01 12:44:10 +02:00
|
|
|
timestamp bool
|
|
|
|
|
ttl bool
|
2017-07-26 13:57:10 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-01 12:44:10 +02:00
|
|
|
func (u using) writeCql(cql *bytes.Buffer) (names []string) {
|
|
|
|
|
if u.timestamp {
|
|
|
|
|
cql.WriteString("USING TIMESTAMP ? ")
|
|
|
|
|
names = append(names, "_ts")
|
2017-07-26 13:57:10 +02:00
|
|
|
}
|
2017-07-27 13:39:27 +02:00
|
|
|
|
2017-08-01 12:44:10 +02:00
|
|
|
if u.ttl {
|
|
|
|
|
if u.timestamp {
|
|
|
|
|
cql.WriteString("AND TTL ? ")
|
2017-07-27 13:39:27 +02:00
|
|
|
} else {
|
2017-08-01 12:44:10 +02:00
|
|
|
cql.WriteString("USING TTL ? ")
|
2017-07-27 13:39:27 +02:00
|
|
|
}
|
2017-08-01 12:44:10 +02:00
|
|
|
names = append(names, "_ttl")
|
2017-07-26 13:57:10 +02:00
|
|
|
}
|
2017-08-01 12:44:10 +02:00
|
|
|
|
|
|
|
|
return
|
2017-07-26 13:57:10 +02:00
|
|
|
}
|
2017-07-27 09:48:33 +02:00
|
|
|
|
2017-07-27 13:39:27 +02:00
|
|
|
type where cmps
|
2017-07-27 09:48:33 +02:00
|
|
|
|
|
|
|
|
func (w where) writeCql(cql *bytes.Buffer) (names []string) {
|
|
|
|
|
if len(w) == 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cql.WriteString("WHERE ")
|
2017-07-27 13:39:27 +02:00
|
|
|
return cmps(w).writeCql(cql)
|
2017-07-27 09:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-27 13:39:27 +02:00
|
|
|
type _if cmps
|
2017-07-27 09:48:33 +02:00
|
|
|
|
|
|
|
|
func (w _if) writeCql(cql *bytes.Buffer) (names []string) {
|
|
|
|
|
if len(w) == 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cql.WriteString("IF ")
|
2017-07-27 13:39:27 +02:00
|
|
|
return cmps(w).writeCql(cql)
|
2017-07-27 09:48:33 +02:00
|
|
|
}
|