diff --git a/qb/select.go b/qb/select.go index 4407ed0..b1cbf0b 100644 --- a/qb/select.go +++ b/qb/select.go @@ -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) diff --git a/qb/select_test.go b/qb/select_test.go index 097ae92..9c7ed9a 100644 --- a/qb/select_test.go +++ b/qb/select_test.go @@ -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")),