-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qb: add named limit and per partition limit clauses
- Loading branch information
Showing
3 changed files
with
87 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters