Support for literals in INSERT and UPDATE and comparisons
The 'value' interface represents a CQL value for use in a comparison, update, or intitialization operation. A consistent interface for this allows us to easily support specifying default-named, custom-named, literal, and evaluated-function values in all these contexts. Parameters to Func should probably also be values to support full composition, but that would be a breaking change because Func's properties are exposed. The value interface could itself be exposed if we wanted to allow clients to pass their own values to SetValue, etc, but for now it is a package-internal abstraction. BLA
This commit is contained in:
committed by
Michał Matczuk
parent
9fa5432a65
commit
12d360a0c3
@@ -36,6 +36,12 @@ func TestUpdateBuilder(t *testing.T) {
|
||||
S: "UPDATE cycling.cyclist_name SET id=?,user_uuid=?,firstname=?,stars=? WHERE id=? ",
|
||||
N: []string{"id", "user_uuid", "firstname", "stars", "expr"},
|
||||
},
|
||||
// Add SET literal
|
||||
{
|
||||
B: Update("cycling.cyclist_name").SetLit("user_uuid", "literal_uuid").Where(w).Set("stars"),
|
||||
S: "UPDATE cycling.cyclist_name SET user_uuid=literal_uuid,stars=? WHERE id=? ",
|
||||
N: []string{"stars", "expr"},
|
||||
},
|
||||
// Add SET SetFunc
|
||||
{
|
||||
B: Update("cycling.cyclist_name").SetFunc("user_uuid", Fn("someFunc", "param_0", "param_1")).Where(w).Set("stars"),
|
||||
@@ -54,6 +60,12 @@ func TestUpdateBuilder(t *testing.T) {
|
||||
S: "UPDATE cycling.cyclist_name SET total=total+? WHERE id=? ",
|
||||
N: []string{"inc", "expr"},
|
||||
},
|
||||
// Add SET AddLit
|
||||
{
|
||||
B: Update("cycling.cyclist_name").AddLit("total", "1").Where(w),
|
||||
S: "UPDATE cycling.cyclist_name SET total=total+1 WHERE id=? ",
|
||||
N: []string{"expr"},
|
||||
},
|
||||
// Add SET Remove
|
||||
{
|
||||
B: Update("cycling.cyclist_name").Remove("total").Where(w),
|
||||
@@ -66,6 +78,12 @@ func TestUpdateBuilder(t *testing.T) {
|
||||
S: "UPDATE cycling.cyclist_name SET total=total-? WHERE id=? ",
|
||||
N: []string{"dec", "expr"},
|
||||
},
|
||||
// Add SET RemoveLit
|
||||
{
|
||||
B: Update("cycling.cyclist_name").RemoveLit("total", "1").Where(w),
|
||||
S: "UPDATE cycling.cyclist_name SET total=total-1 WHERE id=? ",
|
||||
N: []string{"expr"},
|
||||
},
|
||||
// Add WHERE
|
||||
{
|
||||
B: Update("cycling.cyclist_name").Set("id", "user_uuid", "firstname").Where(w, Gt("firstname")),
|
||||
|
||||
Reference in New Issue
Block a user