@@ -103,72 +103,60 @@ func Example() {
103
103
return
104
104
}
105
105
106
+ // Ping a Tarantool instance to check connection
106
107
resp , err := client .Ping ()
107
108
fmt .Println ("Ping Code" , resp .Code )
108
109
fmt .Println ("Ping Data" , resp .Data )
109
110
fmt .Println ("Ping Error" , err )
110
111
111
- // delete tuple for cleaning
112
+ // Delete tuples with primary key { 10 } and { 11 }
112
113
client .Delete (spaceNo , indexNo , []interface {}{uint (10 )})
113
- client .Delete (spaceNo , indexNo , []interface {}{uint (11 )})
114
+ // the same:
115
+ client .Delete ("test" , "primary" , []interface {}{uint (11 )})
114
116
115
- // insert new tuple { 10, 1 }
117
+ // Insert a new tuple { 10, 1 }
116
118
resp , err = client .Insert (spaceNo , []interface {}{uint (10 ), "test" , "one" })
117
- fmt .Println ("Insert Error" , err )
118
- fmt .Println ("Insert Code" , resp .Code )
119
- fmt .Println ("Insert Data" , resp .Data )
120
119
121
- // insert new tuple { 11, 1 }
120
+ // Insert a new tuple { 11, 1 }
122
121
resp , err = client .Insert ("test" , & Tuple {Id : 11 , Msg : "test" , Name : "one" })
123
- fmt .Println ("Insert Error" , err )
124
- fmt .Println ("Insert Code" , resp .Code )
125
- fmt .Println ("Insert Data" , resp .Data )
126
122
127
- // delete tuple with primary key { 10 }
123
+ // Delete a tuple with primary key { 10 }
128
124
resp , err = client .Delete (spaceNo , indexNo , []interface {}{uint (10 )})
129
- // or
130
- // resp, err = client.Delete("test", "primary", UintKey{10}})
131
- fmt .Println ("Delete Error" , err )
132
- fmt .Println ("Delete Code" , resp .Code )
133
- fmt .Println ("Delete Data" , resp .Data )
134
-
135
- // replace tuple with primary key 13
136
- // note, Tuple is defined within tests, and has EncdodeMsgpack and DecodeMsgpack
137
- // methods
125
+ // the same:
126
+ //resp, err = client.Delete("test", "primary", UintKey{10})
127
+
128
+ // Replace tuple with primary key 13.
129
+ // Note, Tuple is defined within tests, and has EncdodeMsgpack and
130
+ // DecodeMsgpack methods.
138
131
resp , err = client .Replace (spaceNo , []interface {}{uint (13 ), 1 })
139
- fmt .Println ("Replace Error" , err )
140
- fmt .Println ("Replace Code" , resp .Code )
141
- fmt .Println ("Replace Data" , resp .Data )
132
+ // the same:
133
+ resp , err = client .Replace ("test" , []interface {}{uint (13 ), 1 })
142
134
143
- // update tuple with primary key { 13 }, incrementing second field by 3
135
+ // Update tuple with primary key { 13 }, incrementing second field by 3
144
136
resp , err = client .Update ("test" , "primary" , tarantool.UintKey {13 }, []tarantool.Op {{"+" , 1 , 3 }})
145
- // or
146
- // resp, err = client.Update(spaceNo, indexNo, []interface{}{uint(13)}, []interface{}{[]interface{}{"+", 1, 3}})
147
- fmt .Println ("Update Error" , err )
148
- fmt .Println ("Update Code" , resp .Code )
149
- fmt .Println ("Update Data" , resp .Data )
137
+ // the same:
138
+ resp , err = client .Update (spaceNo , indexNo , []interface {}{uint (13 )}, []interface {}{[]interface {}{"+" , 1 , 3 }})
150
139
151
- // select just one tuple with primay key { 15 }
140
+ // Select just one tuple with primary key { 15 }
152
141
resp , err = client .Select (spaceNo , indexNo , 0 , 1 , tarantool .IterEq , []interface {}{uint (15 )})
153
- // or
154
- // resp, err = client.Select("test", "primary", 0, 1, tarantool.IterEq, tarantool.UintKey{15})
155
- fmt .Println ("Select Error" , err )
156
- fmt .Println ("Select Code" , resp .Code )
157
- fmt .Println ("Select Data" , resp .Data )
142
+ // the same:
143
+ resp , err = client .Select ("test" , "primary" , 0 , 1 , tarantool .IterEq , tarantool.UintKey {15 })
144
+
145
+ // Select tuples by condition ( primary key > 15 ) with offset 7 and limit 5.
146
+ // BTREE index is supposed.
147
+ resp , err = client .Select (spaceNo , indexNo , 7 , 5 , tarantool .IterGt , []interface {}{uint (15 )})
148
+ // the same:
149
+ resp , err = client .Select ("test" , "primary" , 7 , 5 , tarantool .IterGt , []interface {}{uint (15 )})
158
150
159
- // call function 'func_name' with arguments
151
+ // Call function 'func_name' with arguments
160
152
resp , err = client .Call17 ("simple_incr" , []interface {}{1 })
161
- fmt .Println ("Call17 Error" , err )
162
- fmt .Println ("Call17 Code" , resp .Code )
163
- fmt .Println ("Call17 Data" , resp .Data )
164
153
165
- // run raw Lua code
154
+ // Run raw Lua code
166
155
resp , err = client .Eval ("return 1 + 2" , []interface {}{})
167
- fmt .Println ("Eval Error" , err )
168
- fmt .Println ("Eval Code" , resp .Code )
169
- fmt .Println ("Eval Data" , resp .Data )
170
156
157
+ // Replace
171
158
resp , err = client .Replace ("test" , & Tuple {Id : 11 , Msg : "test" , Name : "eleven" })
159
+ // the same:
172
160
resp , err = client .Replace ("test" , & Tuple {Id : 12 , Msg : "test" , Name : "twelve" })
173
161
174
162
var futs [3 ]* tarantool.Future
@@ -191,34 +179,10 @@ func Example() {
191
179
// Ping Code 0
192
180
// Ping Data []
193
181
// Ping Error <nil>
194
- // Insert Error <nil>
195
- // Insert Code 0
196
- // Insert Data [[10 test one]]
197
- // Insert Error <nil>
198
- // Insert Code 0
199
- // Insert Data [[11 test one]]
200
- // Delete Error <nil>
201
- // Delete Code 0
202
- // Delete Data [[10 test one]]
203
- // Replace Error <nil>
204
- // Replace Code 0
205
- // Replace Data [[13 1]]
206
- // Update Error <nil>
207
- // Update Code 0
208
- // Update Data [[13 4]]
209
- // Select Error <nil>
210
- // Select Code 0
211
- // Select Data [[15 val 15 bla]]
212
- // Call17 Error <nil>
213
- // Call17 Code 0
214
- // Call17 Data [2]
215
- // Eval Error <nil>
216
- // Eval Code 0
217
- // Eval Data [3]
218
182
// Fut 0 Error <nil>
219
183
// Fut 0 Data [{{} 12 test twelve} {{} 11 test eleven}]
220
184
// Fut 1 Error <nil>
221
- // Fut 1 Data [[13 4 ]]
185
+ // Fut 1 Data [[13 7 ]]
222
186
// Fut 2 Error <nil>
223
187
// Fut 2 Data [[15 val 15 bla]]
224
188
}
0 commit comments