qb: tuples now returns the correct names
The names are auto generated in the form param_0, param_1, ...
This commit is contained in:
committed by
Michal Matczuk
parent
219bceab51
commit
1fda6f1e29
@@ -31,7 +31,7 @@ func TestCmp(t *testing.T) {
|
|||||||
{
|
{
|
||||||
C: LtTuple("lt", 2),
|
C: LtTuple("lt", 2),
|
||||||
S: "lt<(?,?)",
|
S: "lt<(?,?)",
|
||||||
N: []string{"lt"},
|
N: []string{"lt_0", "lt_1"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
C: LtOrEq("lt"),
|
C: LtOrEq("lt"),
|
||||||
@@ -41,7 +41,7 @@ func TestCmp(t *testing.T) {
|
|||||||
{
|
{
|
||||||
C: LtOrEqTuple("lt", 2),
|
C: LtOrEqTuple("lt", 2),
|
||||||
S: "lt<=(?,?)",
|
S: "lt<=(?,?)",
|
||||||
N: []string{"lt"},
|
N: []string{"lt_0", "lt_1"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
C: Gt("gt"),
|
C: Gt("gt"),
|
||||||
@@ -51,7 +51,7 @@ func TestCmp(t *testing.T) {
|
|||||||
{
|
{
|
||||||
C: GtTuple("gt", 2),
|
C: GtTuple("gt", 2),
|
||||||
S: "gt>(?,?)",
|
S: "gt>(?,?)",
|
||||||
N: []string{"gt"},
|
N: []string{"gt_0", "gt_1"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
C: GtOrEq("gt"),
|
C: GtOrEq("gt"),
|
||||||
@@ -61,7 +61,7 @@ func TestCmp(t *testing.T) {
|
|||||||
{
|
{
|
||||||
C: GtOrEqTuple("gt", 2),
|
C: GtOrEqTuple("gt", 2),
|
||||||
S: "gt>=(?,?)",
|
S: "gt>=(?,?)",
|
||||||
N: []string{"gt"},
|
N: []string{"gt_0", "gt_1"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
C: In("in"),
|
C: In("in"),
|
||||||
@@ -71,7 +71,7 @@ func TestCmp(t *testing.T) {
|
|||||||
{
|
{
|
||||||
C: InTuple("in", 2),
|
C: InTuple("in", 2),
|
||||||
S: "in IN (?,?)",
|
S: "in IN (?,?)",
|
||||||
N: []string{"in"},
|
N: []string{"in_0", "in_1"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
C: Contains("cnt"),
|
C: Contains("cnt"),
|
||||||
@@ -81,7 +81,7 @@ func TestCmp(t *testing.T) {
|
|||||||
{
|
{
|
||||||
C: ContainsTuple("cnt", 2),
|
C: ContainsTuple("cnt", 2),
|
||||||
S: "cnt CONTAINS (?,?)",
|
S: "cnt CONTAINS (?,?)",
|
||||||
N: []string{"cnt"},
|
N: []string{"cnt_0", "cnt_1"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
C: ContainsKey("cntKey"),
|
C: ContainsKey("cntKey"),
|
||||||
@@ -91,7 +91,7 @@ func TestCmp(t *testing.T) {
|
|||||||
{
|
{
|
||||||
C: ContainsKeyTuple("cntKey", 2),
|
C: ContainsKeyTuple("cntKey", 2),
|
||||||
S: "cntKey CONTAINS KEY (?,?)",
|
S: "cntKey CONTAINS KEY (?,?)",
|
||||||
N: []string{"cntKey"},
|
N: []string{"cntKey_0", "cntKey_1"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
C: Like("like"),
|
C: Like("like"),
|
||||||
@@ -101,7 +101,7 @@ func TestCmp(t *testing.T) {
|
|||||||
{
|
{
|
||||||
C: LikeTuple("like", 2),
|
C: LikeTuple("like", 2),
|
||||||
S: "like LIKE (?,?)",
|
S: "like LIKE (?,?)",
|
||||||
N: []string{"like"},
|
N: []string{"like_0", "like_1"},
|
||||||
},
|
},
|
||||||
|
|
||||||
// Custom bind names
|
// Custom bind names
|
||||||
|
|||||||
@@ -47,19 +47,19 @@ func TestDeleteBuilder(t *testing.T) {
|
|||||||
{
|
{
|
||||||
B: Delete("cycling.cyclist_name").Where(EqTuple("id", 2)).Columns("stars"),
|
B: Delete("cycling.cyclist_name").Where(EqTuple("id", 2)).Columns("stars"),
|
||||||
S: "DELETE stars FROM cycling.cyclist_name WHERE id=(?,?) ",
|
S: "DELETE stars FROM cycling.cyclist_name WHERE id=(?,?) ",
|
||||||
N: []string{"id"},
|
N: []string{"id_0", "id_1"},
|
||||||
},
|
},
|
||||||
// Add WHERE for tuple column
|
// Add WHERE for tuple column
|
||||||
{
|
{
|
||||||
B: Delete("cycling.cyclist_name").Where(w, GtTuple("firstname", 2)),
|
B: Delete("cycling.cyclist_name").Where(w, GtTuple("firstname", 2)),
|
||||||
S: "DELETE FROM cycling.cyclist_name WHERE id=? AND firstname>(?,?) ",
|
S: "DELETE FROM cycling.cyclist_name WHERE id=? AND firstname>(?,?) ",
|
||||||
N: []string{"expr", "firstname"},
|
N: []string{"expr", "firstname_0", "firstname_1"},
|
||||||
},
|
},
|
||||||
// Add WHERE for all tuple columns
|
// Add WHERE for all tuple columns
|
||||||
{
|
{
|
||||||
B: Delete("cycling.cyclist_name").Where(EqTuple("id", 2), GtTuple("firstname", 2)),
|
B: Delete("cycling.cyclist_name").Where(EqTuple("id", 2), GtTuple("firstname", 2)),
|
||||||
S: "DELETE FROM cycling.cyclist_name WHERE id=(?,?) AND firstname>(?,?) ",
|
S: "DELETE FROM cycling.cyclist_name WHERE id=(?,?) AND firstname>(?,?) ",
|
||||||
N: []string{"id", "firstname"},
|
N: []string{"id_0", "id_1", "firstname_0", "firstname_1"},
|
||||||
},
|
},
|
||||||
// Add IF
|
// Add IF
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -80,12 +80,12 @@ func TestInsertBuilder(t *testing.T) {
|
|||||||
{
|
{
|
||||||
B: Insert("cycling.cyclist_name").TupleColumn("id", 2),
|
B: Insert("cycling.cyclist_name").TupleColumn("id", 2),
|
||||||
S: "INSERT INTO cycling.cyclist_name (id) VALUES ((?,?)) ",
|
S: "INSERT INTO cycling.cyclist_name (id) VALUES ((?,?)) ",
|
||||||
N: []string{"id"},
|
N: []string{"id_0", "id_1"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
B: Insert("cycling.cyclist_name").TupleColumn("id", 2).Columns("user_uuid"),
|
B: Insert("cycling.cyclist_name").TupleColumn("id", 2).Columns("user_uuid"),
|
||||||
S: "INSERT INTO cycling.cyclist_name (id,user_uuid) VALUES ((?,?),?) ",
|
S: "INSERT INTO cycling.cyclist_name (id,user_uuid) VALUES ((?,?),?) ",
|
||||||
N: []string{"id", "user_uuid"},
|
N: []string{"id_0", "id_1", "user_uuid"},
|
||||||
},
|
},
|
||||||
// Add IF NOT EXISTS
|
// Add IF NOT EXISTS
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -69,13 +69,13 @@ func TestSelectBuilder(t *testing.T) {
|
|||||||
{
|
{
|
||||||
B: Select("cycling.cyclist_name").Where(EqTuple("id", 2), Gt("firstname")),
|
B: Select("cycling.cyclist_name").Where(EqTuple("id", 2), Gt("firstname")),
|
||||||
S: "SELECT * FROM cycling.cyclist_name WHERE id=(?,?) AND firstname>? ",
|
S: "SELECT * FROM cycling.cyclist_name WHERE id=(?,?) AND firstname>? ",
|
||||||
N: []string{"id", "firstname"},
|
N: []string{"id_0", "id_1", "firstname"},
|
||||||
},
|
},
|
||||||
// Add WHERE with only tuples
|
// Add WHERE with only tuples
|
||||||
{
|
{
|
||||||
B: Select("cycling.cyclist_name").Where(EqTuple("id", 2), GtTuple("firstname", 2)),
|
B: Select("cycling.cyclist_name").Where(EqTuple("id", 2), GtTuple("firstname", 2)),
|
||||||
S: "SELECT * FROM cycling.cyclist_name WHERE id=(?,?) AND firstname>(?,?) ",
|
S: "SELECT * FROM cycling.cyclist_name WHERE id=(?,?) AND firstname>(?,?) ",
|
||||||
N: []string{"id", "firstname"},
|
N: []string{"id_0", "id_1", "firstname_0", "firstname_1"},
|
||||||
},
|
},
|
||||||
// Add GROUP BY
|
// Add GROUP BY
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func TestUpdateBuilder(t *testing.T) {
|
|||||||
{
|
{
|
||||||
B: Update("cycling.cyclist_name").SetTuple("id", 2).Set("user_uuid", "firstname").Where(EqTuple("id", 2)),
|
B: Update("cycling.cyclist_name").SetTuple("id", 2).Set("user_uuid", "firstname").Where(EqTuple("id", 2)),
|
||||||
S: "UPDATE cycling.cyclist_name SET id=(?,?),user_uuid=?,firstname=? WHERE id=(?,?) ",
|
S: "UPDATE cycling.cyclist_name SET id=(?,?),user_uuid=?,firstname=? WHERE id=(?,?) ",
|
||||||
N: []string{"id", "user_uuid", "firstname", "id"},
|
N: []string{"id_0", "id_1", "user_uuid", "firstname", "id_0", "id_1"},
|
||||||
},
|
},
|
||||||
// Add SET SetFunc
|
// Add SET SetFunc
|
||||||
{
|
{
|
||||||
|
|||||||
11
qb/value.go
11
qb/value.go
@@ -4,7 +4,10 @@
|
|||||||
|
|
||||||
package qb
|
package qb
|
||||||
|
|
||||||
import "bytes"
|
import (
|
||||||
|
"bytes"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
// value is a CQL value expression for use in an initializer, assignment,
|
// value is a CQL value expression for use in an initializer, assignment,
|
||||||
// or comparison.
|
// or comparison.
|
||||||
@@ -29,14 +32,18 @@ type tupleParam struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t tupleParam) writeCql(cql *bytes.Buffer) (names []string) {
|
func (t tupleParam) writeCql(cql *bytes.Buffer) (names []string) {
|
||||||
|
baseName := string(t.param) + "_"
|
||||||
cql.WriteByte('(')
|
cql.WriteByte('(')
|
||||||
for i := 0; i < t.count-1; i++ {
|
for i := 0; i < t.count-1; i++ {
|
||||||
cql.WriteByte('?')
|
cql.WriteByte('?')
|
||||||
cql.WriteByte(',')
|
cql.WriteByte(',')
|
||||||
|
names = append(names, baseName+strconv.Itoa(i))
|
||||||
}
|
}
|
||||||
cql.WriteByte('?')
|
cql.WriteByte('?')
|
||||||
cql.WriteByte(')')
|
cql.WriteByte(')')
|
||||||
return []string{string(t.param)}
|
names = append(names, baseName+strconv.Itoa(t.count-1))
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// lit is a literal CQL value.
|
// lit is a literal CQL value.
|
||||||
|
|||||||
Reference in New Issue
Block a user