Skip to content

Commit 6ba176a

Browse files
Add option to add ALLOW FILTERING to the update query (#290)
1 parent c6a436b commit 6ba176a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

qb/update.go

+11
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type UpdateBuilder struct {
3737
_if _if
3838
using using
3939
exists bool
40+
allowFiltering bool
4041
}
4142

4243
// Update returns a new UpdateBuilder with the given table name.
@@ -72,6 +73,10 @@ func (b *UpdateBuilder) ToCql() (stmt string, names []string) {
7273
cql.WriteString("IF EXISTS ")
7374
}
7475

76+
if b.allowFiltering {
77+
cql.WriteString("ALLOW FILTERING ")
78+
}
79+
7580
stmt = cql.String()
7681
return
7782
}
@@ -196,6 +201,12 @@ func (b *UpdateBuilder) AddFunc(column string, fn *Func) *UpdateBuilder {
196201
return b.addValue(column, fn)
197202
}
198203

204+
// AllowFiltering sets a ALLOW FILTERING clause on the query.
205+
func (b *UpdateBuilder) AllowFiltering() *UpdateBuilder {
206+
b.allowFiltering = true
207+
return b
208+
}
209+
199210
func (b *UpdateBuilder) addValue(column string, value value) *UpdateBuilder {
200211
b.assignments = append(b.assignments, assignment{
201212
column: column,

qb/update_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ func TestUpdateBuilder(t *testing.T) {
161161
S: "UPDATE cycling.cyclist_name SET timestamp=timestamp-now() ",
162162
N: nil,
163163
},
164+
// Add ALLOW FILTERING
165+
{
166+
B: Update("cycling.cyclist_name").Set("id", "user_uuid", "firstname").Where(w).AllowFiltering(),
167+
S: "UPDATE cycling.cyclist_name SET id=?,user_uuid=?,firstname=? WHERE id=? ALLOW FILTERING ",
168+
N: []string{"id", "user_uuid", "firstname", "expr"},
169+
},
164170
}
165171

166172
for _, test := range table {

0 commit comments

Comments
 (0)