@@ -27,23 +27,26 @@ func main() {
27
27
28
28
// Interacting with the database
29
29
// Insert data
30
- tuple1 , err := conn .Do (
31
- tarantool .NewInsertRequest ("bands" ).
32
- Tuple ([]interface {}{1 , "Roxette" , 1986 }),
33
- ).Get ()
34
- tuple2 , err := conn .Do (
35
- tarantool .NewInsertRequest ("bands" ).
36
- Tuple ([]interface {}{2 , "Scorpions" , 1965 }),
37
- ).Get ()
38
- tuple3 , err := conn .Do (
39
- tarantool .NewInsertRequest ("bands" ).
40
- Tuple ([]interface {}{3 , "Ace of Base" , 1987 }),
41
- ).Get ()
42
- tuple4 , err := conn .Do (
43
- tarantool .NewInsertRequest ("bands" ).
44
- Tuple ([]interface {}{4 , "The Beatles" , 1960 }),
45
- ).Get ()
46
- fmt .Println ("Inserted tuples: " , tuple1 , tuple2 , tuple3 , tuple4 )
30
+ tuples := [][]interface {}{
31
+ {1 , "Roxette" , 1986 },
32
+ {2 , "Scorpions" , 1965 },
33
+ {3 , "Ace of Base" , 1987 },
34
+ {4 , "The Beatles" , 1960 },
35
+ }
36
+ var futures []* tarantool.Future
37
+ for _ , tuple := range tuples {
38
+ request := tarantool .NewInsertRequest ("bands" ).Tuple (tuple )
39
+ futures = append (futures , conn .Do (request ))
40
+ }
41
+ fmt .Println ("Inserted tuples:" )
42
+ for _ , future := range futures {
43
+ result , err := future .Get ()
44
+ if err != nil {
45
+ fmt .Println ("Got an error:" , err )
46
+ } else {
47
+ fmt .Println (result )
48
+ }
49
+ }
47
50
48
51
// Select by primary key
49
52
data , err := conn .Do (
@@ -52,6 +55,9 @@ func main() {
52
55
Iterator (tarantool .IterEq ).
53
56
Key ([]interface {}{uint (1 )}),
54
57
).Get ()
58
+ if err != nil {
59
+ fmt .Println ("Got an error:" , err )
60
+ }
55
61
fmt .Println ("Tuple selected the primary key value:" , data )
56
62
57
63
// Select by secondary key
@@ -62,6 +68,9 @@ func main() {
62
68
Iterator (tarantool .IterEq ).
63
69
Key ([]interface {}{"The Beatles" }),
64
70
).Get ()
71
+ if err != nil {
72
+ fmt .Println ("Got an error:" , err )
73
+ }
65
74
fmt .Println ("Tuple selected the secondary key value:" , data )
66
75
67
76
// Update
@@ -70,6 +79,9 @@ func main() {
70
79
Key (tarantool.IntKey {2 }).
71
80
Operations (tarantool .NewOperations ().Assign (1 , "Pink Floyd" )),
72
81
).Get ()
82
+ if err != nil {
83
+ fmt .Println ("Got an error:" , err )
84
+ }
73
85
fmt .Println ("Updated tuple:" , data )
74
86
75
87
// Upsert
@@ -78,25 +90,37 @@ func main() {
78
90
Tuple ([]interface {}{uint (5 ), "The Rolling Stones" , 1962 }).
79
91
Operations (tarantool .NewOperations ().Assign (1 , "The Doors" )),
80
92
).Get ()
93
+ if err != nil {
94
+ fmt .Println ("Got an error:" , err )
95
+ }
81
96
82
97
// Replace
83
98
data , err = conn .Do (
84
99
tarantool .NewReplaceRequest ("bands" ).
85
100
Tuple ([]interface {}{1 , "Queen" , 1970 }),
86
101
).Get ()
102
+ if err != nil {
103
+ fmt .Println ("Got an error:" , err )
104
+ }
87
105
fmt .Println ("Replaced tuple:" , data )
88
106
89
107
// Delete
90
108
data , err = conn .Do (
91
109
tarantool .NewDeleteRequest ("bands" ).
92
110
Key ([]interface {}{uint (5 )}),
93
111
).Get ()
112
+ if err != nil {
113
+ fmt .Println ("Got an error:" , err )
114
+ }
94
115
fmt .Println ("Deleted tuple:" , data )
95
116
96
117
// Call
97
118
data , err = conn .Do (
98
119
tarantool .NewCallRequest ("get_bands_older_than" ).Args ([]interface {}{1966 }),
99
120
).Get ()
121
+ if err != nil {
122
+ fmt .Println ("Got an error:" , err )
123
+ }
100
124
fmt .Println ("Stored procedure result:" , data )
101
125
102
126
// Close connection
0 commit comments