Skip to content

Commit 1fda6f1

Browse files
Henrik Johanssonmmatczuk
Henrik Johansson
authored andcommitted
qb: tuples now returns the correct names
The names are auto generated in the form param_0, param_1, ...
1 parent 219bcea commit 1fda6f1

File tree

6 files changed

+25
-18
lines changed

6 files changed

+25
-18
lines changed

qb/cmp_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestCmp(t *testing.T) {
3131
{
3232
C: LtTuple("lt", 2),
3333
S: "lt<(?,?)",
34-
N: []string{"lt"},
34+
N: []string{"lt_0", "lt_1"},
3535
},
3636
{
3737
C: LtOrEq("lt"),
@@ -41,7 +41,7 @@ func TestCmp(t *testing.T) {
4141
{
4242
C: LtOrEqTuple("lt", 2),
4343
S: "lt<=(?,?)",
44-
N: []string{"lt"},
44+
N: []string{"lt_0", "lt_1"},
4545
},
4646
{
4747
C: Gt("gt"),
@@ -51,7 +51,7 @@ func TestCmp(t *testing.T) {
5151
{
5252
C: GtTuple("gt", 2),
5353
S: "gt>(?,?)",
54-
N: []string{"gt"},
54+
N: []string{"gt_0", "gt_1"},
5555
},
5656
{
5757
C: GtOrEq("gt"),
@@ -61,7 +61,7 @@ func TestCmp(t *testing.T) {
6161
{
6262
C: GtOrEqTuple("gt", 2),
6363
S: "gt>=(?,?)",
64-
N: []string{"gt"},
64+
N: []string{"gt_0", "gt_1"},
6565
},
6666
{
6767
C: In("in"),
@@ -71,7 +71,7 @@ func TestCmp(t *testing.T) {
7171
{
7272
C: InTuple("in", 2),
7373
S: "in IN (?,?)",
74-
N: []string{"in"},
74+
N: []string{"in_0", "in_1"},
7575
},
7676
{
7777
C: Contains("cnt"),
@@ -81,7 +81,7 @@ func TestCmp(t *testing.T) {
8181
{
8282
C: ContainsTuple("cnt", 2),
8383
S: "cnt CONTAINS (?,?)",
84-
N: []string{"cnt"},
84+
N: []string{"cnt_0", "cnt_1"},
8585
},
8686
{
8787
C: ContainsKey("cntKey"),
@@ -91,7 +91,7 @@ func TestCmp(t *testing.T) {
9191
{
9292
C: ContainsKeyTuple("cntKey", 2),
9393
S: "cntKey CONTAINS KEY (?,?)",
94-
N: []string{"cntKey"},
94+
N: []string{"cntKey_0", "cntKey_1"},
9595
},
9696
{
9797
C: Like("like"),
@@ -101,7 +101,7 @@ func TestCmp(t *testing.T) {
101101
{
102102
C: LikeTuple("like", 2),
103103
S: "like LIKE (?,?)",
104-
N: []string{"like"},
104+
N: []string{"like_0", "like_1"},
105105
},
106106

107107
// Custom bind names

qb/delete_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ func TestDeleteBuilder(t *testing.T) {
4747
{
4848
B: Delete("cycling.cyclist_name").Where(EqTuple("id", 2)).Columns("stars"),
4949
S: "DELETE stars FROM cycling.cyclist_name WHERE id=(?,?) ",
50-
N: []string{"id"},
50+
N: []string{"id_0", "id_1"},
5151
},
5252
// Add WHERE for tuple column
5353
{
5454
B: Delete("cycling.cyclist_name").Where(w, GtTuple("firstname", 2)),
5555
S: "DELETE FROM cycling.cyclist_name WHERE id=? AND firstname>(?,?) ",
56-
N: []string{"expr", "firstname"},
56+
N: []string{"expr", "firstname_0", "firstname_1"},
5757
},
5858
// Add WHERE for all tuple columns
5959
{
6060
B: Delete("cycling.cyclist_name").Where(EqTuple("id", 2), GtTuple("firstname", 2)),
6161
S: "DELETE FROM cycling.cyclist_name WHERE id=(?,?) AND firstname>(?,?) ",
62-
N: []string{"id", "firstname"},
62+
N: []string{"id_0", "id_1", "firstname_0", "firstname_1"},
6363
},
6464
// Add IF
6565
{

qb/insert_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ func TestInsertBuilder(t *testing.T) {
8080
{
8181
B: Insert("cycling.cyclist_name").TupleColumn("id", 2),
8282
S: "INSERT INTO cycling.cyclist_name (id) VALUES ((?,?)) ",
83-
N: []string{"id"},
83+
N: []string{"id_0", "id_1"},
8484
},
8585
{
8686
B: Insert("cycling.cyclist_name").TupleColumn("id", 2).Columns("user_uuid"),
8787
S: "INSERT INTO cycling.cyclist_name (id,user_uuid) VALUES ((?,?),?) ",
88-
N: []string{"id", "user_uuid"},
88+
N: []string{"id_0", "id_1", "user_uuid"},
8989
},
9090
// Add IF NOT EXISTS
9191
{

qb/select_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ func TestSelectBuilder(t *testing.T) {
6969
{
7070
B: Select("cycling.cyclist_name").Where(EqTuple("id", 2), Gt("firstname")),
7171
S: "SELECT * FROM cycling.cyclist_name WHERE id=(?,?) AND firstname>? ",
72-
N: []string{"id", "firstname"},
72+
N: []string{"id_0", "id_1", "firstname"},
7373
},
7474
// Add WHERE with only tuples
7575
{
7676
B: Select("cycling.cyclist_name").Where(EqTuple("id", 2), GtTuple("firstname", 2)),
7777
S: "SELECT * FROM cycling.cyclist_name WHERE id=(?,?) AND firstname>(?,?) ",
78-
N: []string{"id", "firstname"},
78+
N: []string{"id_0", "id_1", "firstname_0", "firstname_1"},
7979
},
8080
// Add GROUP BY
8181
{

qb/update_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestUpdateBuilder(t *testing.T) {
4848
{
4949
B: Update("cycling.cyclist_name").SetTuple("id", 2).Set("user_uuid", "firstname").Where(EqTuple("id", 2)),
5050
S: "UPDATE cycling.cyclist_name SET id=(?,?),user_uuid=?,firstname=? WHERE id=(?,?) ",
51-
N: []string{"id", "user_uuid", "firstname", "id"},
51+
N: []string{"id_0", "id_1", "user_uuid", "firstname", "id_0", "id_1"},
5252
},
5353
// Add SET SetFunc
5454
{

qb/value.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
package qb
66

7-
import "bytes"
7+
import (
8+
"bytes"
9+
"strconv"
10+
)
811

912
// value is a CQL value expression for use in an initializer, assignment,
1013
// or comparison.
@@ -29,14 +32,18 @@ type tupleParam struct {
2932
}
3033

3134
func (t tupleParam) writeCql(cql *bytes.Buffer) (names []string) {
35+
baseName := string(t.param) + "_"
3236
cql.WriteByte('(')
3337
for i := 0; i < t.count-1; i++ {
3438
cql.WriteByte('?')
3539
cql.WriteByte(',')
40+
names = append(names, baseName+strconv.Itoa(i))
3641
}
3742
cql.WriteByte('?')
3843
cql.WriteByte(')')
39-
return []string{string(t.param)}
44+
names = append(names, baseName+strconv.Itoa(t.count-1))
45+
46+
return
4047
}
4148

4249
// lit is a literal CQL value.

0 commit comments

Comments
 (0)