Add option to add ALLOW FILTERING to the update query (#290)
This commit is contained in:
11
qb/update.go
11
qb/update.go
@@ -37,6 +37,7 @@ type UpdateBuilder struct {
|
|||||||
_if _if
|
_if _if
|
||||||
using using
|
using using
|
||||||
exists bool
|
exists bool
|
||||||
|
allowFiltering bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update returns a new UpdateBuilder with the given table name.
|
// Update returns a new UpdateBuilder with the given table name.
|
||||||
@@ -72,6 +73,10 @@ func (b *UpdateBuilder) ToCql() (stmt string, names []string) {
|
|||||||
cql.WriteString("IF EXISTS ")
|
cql.WriteString("IF EXISTS ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if b.allowFiltering {
|
||||||
|
cql.WriteString("ALLOW FILTERING ")
|
||||||
|
}
|
||||||
|
|
||||||
stmt = cql.String()
|
stmt = cql.String()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -196,6 +201,12 @@ func (b *UpdateBuilder) AddFunc(column string, fn *Func) *UpdateBuilder {
|
|||||||
return b.addValue(column, fn)
|
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 {
|
func (b *UpdateBuilder) addValue(column string, value value) *UpdateBuilder {
|
||||||
b.assignments = append(b.assignments, assignment{
|
b.assignments = append(b.assignments, assignment{
|
||||||
column: column,
|
column: column,
|
||||||
|
|||||||
@@ -161,6 +161,12 @@ func TestUpdateBuilder(t *testing.T) {
|
|||||||
S: "UPDATE cycling.cyclist_name SET timestamp=timestamp-now() ",
|
S: "UPDATE cycling.cyclist_name SET timestamp=timestamp-now() ",
|
||||||
N: nil,
|
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 {
|
for _, test := range table {
|
||||||
|
|||||||
Reference in New Issue
Block a user