| tag | 835716d46782ed3688c2e24a484f1ff15b20514e | |
|---|---|---|
| tagger | Christoph Hack <christoph@tux21b.org> | Wed Jul 16 10:39:06 2014 +0200 |
| object | 162ac032e491df376b4727d9d434a78ddd0f1266 |
tagged last go1.1 compatible version
| commit | 162ac032e491df376b4727d9d434a78ddd0f1266 | [log] [tgz] |
|---|---|---|
| author | Ben Hood <0x6e6562@gmail.com> | Tue Jul 15 09:13:41 2014 +0100 |
| committer | Ben Hood <0x6e6562@gmail.com> | Tue Jul 15 09:13:41 2014 +0100 |
| tree | efad1db58156360e1b1a99bb4dc02ccdf0de577c | |
| parent | 20ba163d1ee6e2123dcf311a774c499ca3624fa1 [diff] | |
| parent | d0d29fe034d600c0a98a7ebd06cddd5a81089d6f [diff] |
Merge pull request #194 from phillipCouto/cass1.2-fails Added skip statements for tests using batchs when proto = 1
Package Status: Alpha
Package gocql implements a fast and robust Cassandra client for the Go programming language.
Project Website: http://gocql.github.io/
API documentation: http://godoc.org/github.com/gocql/gocql
Discussions: https://groups.google.com/forum/#!forum/gocql
go get github.com/gocql/gocql
Marshaler and Unmarshaler interfacePlease visit the Roadmap page to see what is on the horizion.
gocql no longer supports executing “use ” statements to simplfy the library. The user still has the ability to define the default keyspace for connections but now the keyspace can only be defined before a session is created. Queries can still access keyspaces by indicating the keyspace in the query:
SELECT * FROM example2.table;
Example of correct usage:
cluster := gocql.NewCluster("192.168.1.1", "192.168.1.2", "192.168.1.3")
cluster.Keyspace = "example"
...
session, err := cluster.CreateSession()
Example of incorrect usage:
cluster := gocql.NewCluster("192.168.1.1", "192.168.1.2", "192.168.1.3")
cluster.Keyspace = "example"
...
session, err := cluster.CreateSession()
if err = session.Query("use example2").Exec(); err != nil {
log.Fatal(err)
}
This will result in an err being returned from the session.Query line as the user is trying to execute a “use” statement.
package main import ( "fmt" "log" "github.com/gocql/gocql" ) func main() { // connect to the cluster cluster := gocql.NewCluster("192.168.1.1", "192.168.1.2", "192.168.1.3") cluster.Keyspace = "example" cluster.Consistency = gocql.Quorum session, _ := cluster.CreateSession() defer session.Close() // insert a tweet if err := session.Query(`INSERT INTO tweet (timeline, id, text) VALUES (?, ?, ?)`, "me", gocql.TimeUUID(), "hello world").Exec(); err != nil { log.Fatal(err) } var id gocql.UUID var text string // select a single tweet if err := session.Query(`SELECT id, text FROM tweet WHERE timeline = ? LIMIT 1`, "me").Consistency(gocql.One).Scan(&id, &text); err != nil { log.Fatal(err) } fmt.Println("Tweet:", id, text) // list all tweets iter := session.Query(`SELECT id, text FROM tweet WHERE timeline = ?`, "me").Iter() for iter.Scan(&id, &text) { fmt.Println("Tweet:", id, text) } if err := iter.Close(); err != nil { log.Fatal(err) } }
Copyright (c) 2012-2014 The gocql Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.