qb: add named limit and per partition limit clauses
This commit is contained in:
committed by
Michal Jan Matczuk
parent
e182c6eeff
commit
beeab600f9
45
qb/limit.go
Normal file
45
qb/limit.go
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2017 ScyllaDB
|
||||
// Use of this source code is governed by a ALv2-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package qb
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type limit struct {
|
||||
value value
|
||||
perPartition bool
|
||||
}
|
||||
|
||||
func limitLit(l uint, perPartition bool) limit {
|
||||
val := strconv.FormatUint(uint64(l), 10)
|
||||
return limit{
|
||||
value: lit(val),
|
||||
perPartition: perPartition,
|
||||
}
|
||||
}
|
||||
|
||||
func limitNamed(name string, perPartition bool) limit {
|
||||
return limit{
|
||||
value: param(name),
|
||||
perPartition: perPartition,
|
||||
}
|
||||
}
|
||||
|
||||
func (l limit) writeCql(cql *bytes.Buffer) (names []string) {
|
||||
if l.value == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if l.perPartition {
|
||||
cql.WriteString("PER PARTITION ")
|
||||
}
|
||||
cql.WriteString("LIMIT ")
|
||||
|
||||
names = l.value.writeCql(cql)
|
||||
cql.WriteByte(' ')
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user