| commit | 20ba163d1ee6e2123dcf311a774c499ca3624fa1 | [log] [tgz] |
|---|---|---|
| author | Phillip Couto <phillip.couto@stemstudios.com> | Wed Jul 09 10:25:03 2014 -0400 |
| committer | Phillip Couto <phillip.couto@stemstudios.com> | Wed Jul 09 10:25:03 2014 -0400 |
| tree | b84796df030b0f4942166bfacf39bbc794e457a4 | |
| parent | 537bb3981c07ddbbe763aa1b0bf2162b7ceea87e [diff] | |
| parent | 5e5d698a1b084727bd8c1cbf872c2ce10f921338 [diff] |
Merge pull request #192 from relops/verify_query_arg_length Prevent query argument length mismatches causing a panic
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.