Skip to content

Commit

Permalink
Add option to add ALLOW FILTERING to the update query (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylwiaszunejko authored Sep 10, 2024
1 parent c6a436b commit 6ba176a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions qb/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type UpdateBuilder struct {
_if _if
using using
exists bool
allowFiltering bool
}

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

if b.allowFiltering {
cql.WriteString("ALLOW FILTERING ")
}

stmt = cql.String()
return
}
Expand Down Expand Up @@ -196,6 +201,12 @@ func (b *UpdateBuilder) AddFunc(column string, fn *Func) *UpdateBuilder {
return b.addValue(column, fn)
}

// AllowFiltering sets a ALLOW FILTERING clause on the query.
func (b *UpdateBuilder) AllowFiltering() *UpdateBuilder {
b.allowFiltering = true
return b
}

func (b *UpdateBuilder) addValue(column string, value value) *UpdateBuilder {
b.assignments = append(b.assignments, assignment{
column: column,
Expand Down
6 changes: 6 additions & 0 deletions qb/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ func TestUpdateBuilder(t *testing.T) {
S: "UPDATE cycling.cyclist_name SET timestamp=timestamp-now() ",
N: nil,
},
// Add ALLOW FILTERING
{
B: Update("cycling.cyclist_name").Set("id", "user_uuid", "firstname").Where(w).AllowFiltering(),
S: "UPDATE cycling.cyclist_name SET id=?,user_uuid=?,firstname=? WHERE id=? ALLOW FILTERING ",
N: []string{"id", "user_uuid", "firstname", "expr"},
},
}

for _, test := range table {
Expand Down

0 comments on commit 6ba176a

Please sign in to comment.