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:
committed by
Michal Jan Matczuk
parent
96a8de1e1e
commit
979397bc5e
18
qb/select.go
18
qb/select.go
@@ -11,6 +11,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/scylladb/gocqlx/v2"
|
||||
)
|
||||
@@ -37,6 +38,7 @@ type SelectBuilder struct {
|
||||
table string
|
||||
columns columns
|
||||
distinct columns
|
||||
using using
|
||||
where where
|
||||
groupBy columns
|
||||
orderBy columns
|
||||
@@ -83,7 +85,8 @@ func (b *SelectBuilder) ToCql() (stmt string, names []string) {
|
||||
cql.WriteString(b.table)
|
||||
cql.WriteByte(' ')
|
||||
|
||||
names = b.where.writeCql(&cql)
|
||||
names = append(names, b.using.writeCql(&cql)...)
|
||||
names = append(names, b.where.writeCql(&cql)...)
|
||||
|
||||
if len(b.groupBy) > 0 {
|
||||
cql.WriteString("GROUP BY ")
|
||||
@@ -168,6 +171,19 @@ func (b *SelectBuilder) Distinct(columns ...string) *SelectBuilder {
|
||||
return b
|
||||
}
|
||||
|
||||
// Timeout adds USING TIMEOUT clause to the query.
|
||||
func (b *SelectBuilder) Timeout(d time.Duration) *SelectBuilder {
|
||||
b.using.Timeout(d)
|
||||
return b
|
||||
}
|
||||
|
||||
// TimeoutNamed adds a USING TIMEOUT clause to the query with a custom
|
||||
// parameter name.
|
||||
func (b *SelectBuilder) TimeoutNamed(name string) *SelectBuilder {
|
||||
b.using.TimeoutNamed(name)
|
||||
return b
|
||||
}
|
||||
|
||||
// Where adds an expression to the WHERE clause of the query. Expressions are
|
||||
// ANDed together in the generated CQL.
|
||||
func (b *SelectBuilder) Where(w ...Cmp) *SelectBuilder {
|
||||
|
||||
Reference in New Issue
Block a user