qb: add named limit and per partition limit clauses

This commit is contained in:
Nikita Karmatskikh
2021-11-21 01:00:39 +03:00
committed by Michal Jan Matczuk
parent e182c6eeff
commit beeab600f9
3 changed files with 87 additions and 16 deletions

45
qb/limit.go Normal file
View 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
}