@@ -226,73 +226,7 @@ statement.
226
226
Example
227
227
-------
228
228
229
- ``` go
230
- /* Before you execute the program, Launch `cqlsh` and execute:
231
- create keyspace example with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
232
- create table example.tweet(timeline text, id UUID, text text, PRIMARY KEY(id));
233
- create index on example.tweet(timeline);
234
- */
235
- package main
236
-
237
- import (
238
- " fmt"
239
- " log"
240
-
241
- " github.com/scylladb/gocql"
242
- )
243
-
244
- func main () {
245
- // connect to the cluster
246
- cluster := gocql.NewCluster (" 192.168.1.1" , " 192.168.1.2" , " 192.168.1.3" )
247
- cluster.Keyspace = " example"
248
- cluster.Consistency = gocql.Quorum
249
- session , _ := cluster.CreateSession ()
250
- defer session.Close ()
251
-
252
- // insert a tweet
253
- if err := session.Query (` INSERT INTO tweet (timeline, id, text) VALUES (?, ?, ?)` ,
254
- " me" , gocql.TimeUUID (), " hello world" ).Exec (); err != nil {
255
- log.Fatal (err)
256
- }
257
-
258
- var id gocql.UUID
259
- var text string
260
-
261
- /* Search for a specific set of records whose 'timeline' column matches
262
- * the value 'me'. The secondary index that we created earlier will be
263
- * used for optimizing the search */
264
- if err := session.Query (` SELECT id, text FROM tweet WHERE timeline = ? LIMIT 1` ,
265
- " me" ).Consistency (gocql.One ).Scan (&id, &text); err != nil {
266
- log.Fatal (err)
267
- }
268
- fmt.Println (" Tweet:" , id, text)
269
-
270
- // list all tweets
271
- iter := session.Query (` SELECT id, text FROM tweet WHERE timeline = ?` , " me" ).Iter ()
272
- for iter.Scan (&id, &text) {
273
- fmt.Println (" Tweet:" , id, text)
274
- }
275
- if err := iter.Close (); err != nil {
276
- log.Fatal (err)
277
- }
278
- }
279
- ```
280
-
281
-
282
- Authentication
283
- -------
284
-
285
- ``` go
286
- cluster := gocql.NewCluster (" 192.168.1.1" , " 192.168.1.2" , " 192.168.1.3" )
287
- cluster.Authenticator = gocql.PasswordAuthenticator {
288
- Username : " user" ,
289
- Password : " password"
290
- }
291
- cluster.Keyspace = " example"
292
- cluster.Consistency = gocql.Quorum
293
- session , _ := cluster.CreateSession ()
294
- defer session.Close ()
295
- ```
229
+ See [ package documentation] ( https://pkg.go.dev/github.com/scylladb/gocql#pkg-examples ) .
296
230
297
231
Data Binding
298
232
------------
0 commit comments