|
|
11 years ago | |
|---|---|---|
| website | 12 years ago | |
| .gitignore | 11 years ago | |
| .travis.yml | 11 years ago | |
| AUTHORS | 11 years ago | |
| CONTRIBUTING.md | 11 years ago | |
| LICENSE | 13 years ago | |
| README.md | 11 years ago | |
| cass1batch_test.go | 11 years ago | |
| cassandra_test.go | 11 years ago | |
| cluster.go | 11 years ago | |
| compressor.go | 11 years ago | |
| conn.go | 11 years ago | |
| conn_go11.go | 11 years ago | |
| conn_go12.go | 11 years ago | |
| conn_test.go | 11 years ago | |
| connectionpool.go | 11 years ago | |
| doc.go | 12 years ago | |
| errors.go | 11 years ago | |
| errors_test.go | 11 years ago | |
| frame.go | 11 years ago | |
| helpers.go | 11 years ago | |
| integration.sh | 11 years ago | |
| marshal.go | 11 years ago | |
| marshal_test.go | 11 years ago | |
| policies.go | 11 years ago | |
| session.go | 11 years ago | |
| topology.go | 12 years ago | |
| uuid.go | 11 years ago | |
| uuid_test.go | 11 years ago |
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.