DataDog/gocql

Name: gocql

Owner: Datadog, Inc.

Description: Package gocql implements a fast and robust Cassandra client for the Go programming language.

Created: 2015-11-23 19:15:18.0

Updated: 2016-07-19 19:27:37.0

Pushed: 2017-11-21 18:30:18.0

Homepage: http://gocql.github.io/

Size: 2441

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

gocql

Join the chat at https://gitter.im/gocql/gocql Build Status GoDoc

Package gocql implements a fast and robust Cassandra client for the Go programming language.

Project Website: https://gocql.github.io/
API documentation: https://godoc.org/github.com/gocql/gocql
Discussions: https://groups.google.com/forum/#!forum/gocql

Supported Versions

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 | 2.1.x | 2.2.x | 3.0.x ————-| ——-| ——| ——— 1.8 | yes | yes | yes 1.9 | yes | yes | yes

Gocql has been tested in production against many different versions of Cassandra. Due to limits in our CI setup we only test against the latest 3 major releases, which coincide with the official support from the Apache project.

Sunsetting Model

In general, the gocql team will focus on supporting the current and previous versions of Go. gocql may still work with older versions of Go, but official support for these versions will have been sunset.

Installation
go get github.com/gocql/gocql
Features
Performance

While the driver strives to be highly performant, there are cases where it is difficult to test and verify. The driver is built with maintainability and code readability in mind first and then performance and features, as such every now and then performance may degrade, if this occurs please report and issue and it will be looked at and remedied. The only time the driver copies data from its read buffer is when it Unmarshal's data into supplied types.

Some tips for getting more performance from the driver:

Important Default Keyspace Changes

gocql no longer supports executing “use ” statements to simplify 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:

CT * 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.

Example
efore you execute the program, Launch `cqlsh` and execute:
te keyspace example with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
te table example.tweet(timeline text, id UUID, text text, PRIMARY KEY(id));
te index on example.tweet(timeline);

age main

rt (
"fmt"
"log"

"github.com/gocql/gocql"


 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)
}

Data Binding

There are various ways to bind application level data structures to CQL statements:

Ecosystem

The following community maintained tools are known to integrate with gocql:

Other Projects
SEO

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.

License

Copyright (c) 2012-2016 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.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.