|
|
10 年之前 | |
|---|---|---|
| testdata | 11 年之前 | |
| website | 12 年之前 | |
| .gitignore | 11 年之前 | |
| .travis.yml | 10 年之前 | |
| AUTHORS | 10 年之前 | |
| CONTRIBUTING.md | 11 年之前 | |
| LICENSE | 13 年之前 | |
| README.md | 11 年之前 | |
| cass1batch_test.go | 11 年之前 | |
| cassandra_test.go | 10 年之前 | |
| cluster.go | 10 年之前 | |
| compressor.go | 11 年之前 | |
| compressor_test.go | 11 年之前 | |
| conn.go | 10 年之前 | |
| conn_test.go | 11 年之前 | |
| connectionpool.go | 11 年之前 | |
| doc.go | 12 年之前 | |
| errors.go | 11 年之前 | |
| errors_test.go | 11 年之前 | |
| frame.go | 11 年之前 | |
| helpers.go | 10 年之前 | |
| host_source.go | 11 年之前 | |
| integration.sh | 11 年之前 | |
| marshal.go | 11 年之前 | |
| marshal_test.go | 10 年之前 | |
| policies.go | 11 年之前 | |
| session.go | 11 年之前 | |
| session_test.go | 11 年之前 | |
| topology.go | 12 年之前 | |
| topology_test.go | 11 年之前 | |
| uuid.go | 11 年之前 | |
| uuid_test.go | 11 年之前 | |
| wiki_test.go | 11 年之前 |
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
The following matrix shows the versions of Go and Cassandra that are tested with the integration test suite as part of the CI build:
| Go/Cassandra | 1.2.19 | 2.0.11 | 2.1.2 |
|---|---|---|---|
| 1.2 | yes | yes | yes |
| 1.3 | yes | yes | yes |
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.
/* Before you execute the program, Launch `cqlsh` and execute:
create keyspace example with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
create table example.tweet(timeline text, id UUID, text text, PRIMARY KEY(id));
create index on example.tweet(timeline);
*/
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
/* Search for a specific set of records whose 'timeline' column matches
* the value 'me'. The secondary index that we created earlier will be
* used for optimizing the search */
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)
}
}
There are various ways to bind application level data structures to CQL statements:
[]map[string]interface{} using the SliceMap() API. This returns a slice of row maps keyed by CQL column mames. This method requires no special interaction with the gocql API, but it does require your application to be able to deal with a key value view of your data.SliceMap() API you can also call MapScan() which returns map[string]interface{} instances in a row by row fashion.Bind() API provides a client app with a low level mechanism to introspect query meta data and extract appropriate field values from application level data structures.The following community maintained tools are known to integrate with gocql:
For some reason, when you google golang cassandra, this project doesn't feature very highly in the result list. But if you google go cassandra, then we're a bit higher up the list. So this is note to try to convince Google that Golang is an alias for Go.
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.