Add support for BYPASS CACHE

This commit adds support for BYPASS CACHE extension that is present in
ScyllaDB since 3.1 / 2019.1.1.

https://docs.scylladb.com/getting-started/dml/#bypass-cache
This commit is contained in:
Martin Sucha
2019-09-16 16:33:41 +02:00
committed by Michal Matczuk
parent dd98b0e363
commit 75adfd59ee
2 changed files with 26 additions and 0 deletions

View File

@@ -40,6 +40,7 @@ type SelectBuilder struct {
limit uint
limitPerPartition uint
allowFiltering bool
bypassCache bool
json bool
}
@@ -109,6 +110,10 @@ func (b *SelectBuilder) ToCql() (stmt string, names []string) {
cql.WriteString("ALLOW FILTERING ")
}
if b.bypassCache {
cql.WriteString("BYPASS CACHE ")
}
stmt = cql.String()
return
}
@@ -180,6 +185,15 @@ func (b *SelectBuilder) AllowFiltering() *SelectBuilder {
return b
}
// BypassCache sets a BYPASS CACHE clause on the query.
//
// BYPASS CACHE is a feature specific to ScyllaDB.
// See https://docs.scylladb.com/getting-started/dml/#bypass-cache
func (b *SelectBuilder) BypassCache() *SelectBuilder {
b.bypassCache = true
return b
}
// Count produces 'count(column)'.
func (b *SelectBuilder) Count(column string) *SelectBuilder {
b.fn("count", column)

View File

@@ -128,6 +128,18 @@ func TestSelectBuilder(t *testing.T) {
S: "SELECT * FROM cycling.cyclist_name WHERE id=? ALLOW FILTERING ",
N: []string{"expr"},
},
// Add ALLOW FILTERING and BYPASS CACHE
{
B: Select("cycling.cyclist_name").Where(w).AllowFiltering().BypassCache(),
S: "SELECT * FROM cycling.cyclist_name WHERE id=? ALLOW FILTERING BYPASS CACHE ",
N: []string{"expr"},
},
// Add BYPASS CACHE
{
B: Select("cycling.cyclist_name").Where(w).BypassCache(),
S: "SELECT * FROM cycling.cyclist_name WHERE id=? BYPASS CACHE ",
N: []string{"expr"},
},
// Add COUNT all
{
B: Select("cycling.cyclist_name").CountAll().Where(Gt("stars")),