apache / cassandra-gocql-driver

GoCQL Driver for Apache Cassandra®
https://cassandra.apache.org/
Apache License 2.0
2.59k stars 622 forks source link
cassandra client database driver go golang nosql

Apache Cassandra GoCQL Driver

!Join the chat at https://the-asf.slack.com/archives/C05LPRVNZV1 go build GoDoc

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

Project Website: https://cassandra.apache.org
API documentation: https://godoc.org/github.com/gocql/gocql
Discussions: https://cassandra.apache.org/_/community.html#discussions

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 4.0.x 4.1.x
1.22 yes yes
1.23 yes yes

Gocql has been tested in production against many versions of Cassandra. Due to limits in our CI setup we only test against the latest 2 GA releases.

Sunsetting Model

In general, the Cassandra community 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:

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.

Example

See package documentation.

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.