Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions qb/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}

// SelectBuilder builds CQL SELECT statements.
type SelectBuilder struct {

Check failure on line 36 in qb/select.go

View workflow job for this annotation

GitHub Actions / Build

fieldalignment: struct with 264 pointer bytes could be 256 (govet)
limit limit
limitPerPartition limit
table string
Expand Down Expand Up @@ -175,6 +175,12 @@
return b
}

// ServiceLevel adds a USING SERVICE LEVEL clause with the given name to the query
func (b *SelectBuilder) ServiceLevel(name string) *SelectBuilder {
b.using.ServiceLevel(name)
return b
}
Comment on lines +178 to +182

// 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 {
Expand Down
12 changes: 12 additions & 0 deletions qb/using.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import (
"bytes"
"fmt"
"strings"
"time"
)

Expand All @@ -20,13 +21,14 @@
return t.UnixNano() / 1000
}

type using struct {

Check failure on line 24 in qb/using.go

View workflow job for this annotation

GitHub Actions / Build

fieldalignment: struct with 80 pointer bytes could be 56 (govet)
ttlName string
timestampName string
timeoutName string
ttl int64
timestamp int64
timeout time.Duration
serviceLevel string
}

func (u *using) TTL(d time.Duration) *using {
Expand Down Expand Up @@ -68,6 +70,11 @@
return u
}

func (u *using) ServiceLevel(name string) *using {
u.serviceLevel = name
return u
}

func (u *using) writeCql(cql *bytes.Buffer) (names []string) {
writePreamble := u.preambleWriter()

Expand Down Expand Up @@ -101,6 +108,11 @@
names = append(names, u.timeoutName)
}

if u.serviceLevel != "" {
writePreamble(cql)
fmt.Fprintf(cql, "SERVICE LEVEL '%s' ", strings.ReplaceAll(u.serviceLevel, "'", "''"))
}

return
}

Expand Down
15 changes: 15 additions & 0 deletions qb/using_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ func TestUsing(t *testing.T) {
B: new(using).TimestampNamed("ts").Timestamp(time.Date(2005, 5, 5, 0, 0, 0, 0, time.UTC)),
S: "USING TIMESTAMP 1115251200000000 ",
},
// ServiceLevel
{
B: new(using).ServiceLevel("foo"),
S: "USING SERVICE LEVEL 'foo' ",
},
// ServiceLevel with additional Timeout
{
B: new(using).ServiceLevel("foo").Timeout(time.Second),
S: "USING TIMEOUT 1s AND SERVICE LEVEL 'foo' ",
},
// ServiceLevel with a silly, but legal, name
{
B: new(using).ServiceLevel(`^&*^\!@#&($%^!';[](+`),
S: `USING SERVICE LEVEL '^&*^\!@#&($%^!'';[](+' `,
},
}

for _, test := range table {
Expand Down
Loading