forked from scylladb/gocql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for handling tuple types
Add basic support to handling scanning of tuples. This changes the Scan logic such that tuple columns are scanned as if they were defined as ordinary columns.
- Loading branch information
Showing
6 changed files
with
194 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// +build all integration | ||
|
||
package gocql | ||
|
||
import "testing" | ||
|
||
func TestTupleSimple(t *testing.T) { | ||
if *flagProto < protoVersion3 { | ||
t.Skip("tuple types are only available of proto>=3") | ||
} | ||
|
||
session := createSession(t) | ||
defer session.Close() | ||
|
||
err := createTable(session, `CREATE TABLE tuple_test( | ||
id int, | ||
coord frozen<tuple<int, int>>, | ||
primary key(id))`) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = session.Query("INSERT INTO tuple_test(id, coord) VALUES(?, (?, ?))", 1, 100, -100).Exec() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
var ( | ||
id int | ||
coord struct { | ||
x int | ||
y int | ||
} | ||
) | ||
|
||
iter := session.Query("SELECT id, coord FROM tuple_test WHERE id=?", 1) | ||
if err := iter.Scan(&id, &coord.x, &coord.y); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if id != 1 { | ||
t.Errorf("expected to get id=1 got: %v", id) | ||
} | ||
if coord.x != 100 { | ||
t.Errorf("expected to get coord.x=100 got: %v", coord.x) | ||
} | ||
if coord.y != -100 { | ||
t.Errorf("expected to get coord.y=-100 got: %v", coord.y) | ||
} | ||
} |