Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to add ALLOW FILTERING to the update query #290

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading