qb: add support for USING TIMEOUT clause

In scylladb/scylla#7781 we added possibility to add timeout as part of USING spec.
This patch adds support for it by adding `Timeout` and `TimeoutNamed` functions to builders.

Fixes #194
This commit is contained in:
Michał Matczuk
2021-08-03 11:29:54 +02:00
committed by Michal Jan Matczuk
parent 96a8de1e1e
commit 979397bc5e
12 changed files with 198 additions and 2 deletions

View File

@@ -25,7 +25,10 @@ type using struct {
ttlName string
timestamp int64
timestampName string
using bool
timeout time.Duration
timeoutName string
using bool
}
func (u *using) TTL(d time.Duration) *using {
@@ -55,6 +58,18 @@ func (u *using) TimestampNamed(name string) *using {
return u
}
func (u *using) Timeout(d time.Duration) *using {
u.timeout = d
u.timeoutName = ""
return u
}
func (u *using) TimeoutNamed(name string) *using {
u.timeout = 0
u.timeoutName = name
return u
}
func (u *using) writeCql(cql *bytes.Buffer) (names []string) {
u.using = false
@@ -79,6 +94,15 @@ func (u *using) writeCql(cql *bytes.Buffer) (names []string) {
names = append(names, u.timestampName)
}
if u.timeout != 0 {
u.writePreamble(cql)
fmt.Fprintf(cql, "TIMEOUT %s ", u.timeout)
} else if u.timeoutName != "" {
u.writePreamble(cql)
cql.WriteString("TIMEOUT ? ")
names = append(names, u.timeoutName)
}
return
}