• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..25-Jul-2019-

internal/H25-Jul-2019-433307

.gitignoreH A D25-Jul-201950 65

.travis.ymlH A D25-Jul-2019626 4838

AUTHORSH A D25-Jul-20194.3 KiB114112

CONTRIBUTING.mdH A D25-Jul-20195.7 KiB7946

LICENSEH A D25-Jul-20191.5 KiB2822

README.mdH A D25-Jul-201910.7 KiB216174

address_translators.goH A D25-Jul-2019955 2714

cluster.goH A D25-Jul-201910.6 KiB21298

compressor.goH A D25-Jul-2019680 2919

conn.goH A D25-Jul-201933 KiB1,4461,116

connectionpool.goH A D25-Jul-201912.8 KiB582406

control.goH A D25-Jul-20199.9 KiB486366

cqltypes.goH A D25-Jul-2019264 126

debug_off.goH A D25-Jul-201964 62

debug_on.goH A D25-Jul-201962 62

doc.goH A D25-Jul-2019355 101

errors.goH A D25-Jul-20192.2 KiB126105

events.goH A D25-Jul-20196.6 KiB294226

filters.goH A D25-Jul-20191.6 KiB5837

frame.goH A D25-Jul-201944.9 KiB2,1041,650

fuzz.goH A D25-Jul-2019436 3423

go.modH A D25-Jul-2019196 86

go.modverifyH A D25-Jul-2019294 43

helpers.goH A D25-Jul-201910.3 KiB433347

host_source.goH A D25-Jul-201915.6 KiB703573

host_source_gen.goH A D25-Jul-2019783 4636

install_test_deps.shH A D25-Jul-2019337 1710

integration.shH A D25-Jul-20192.4 KiB9171

logger.goH A D25-Jul-2019941 3123

marshal.goH A D25-Jul-201956.4 KiB2,3942,086

metadata.goH A D25-Jul-201931.1 KiB1,3331,054

policies.goH A D25-Jul-201921.6 KiB887634

prepared_cache.goH A D25-Jul-20191.2 KiB6547

query_executor.goH A D25-Jul-20193.7 KiB162119

ring.goH A D25-Jul-20193 KiB153119

session.goH A D25-Jul-201953.2 KiB1,9741,319

token.goH A D25-Jul-20194.9 KiB221163

topology.goH A D25-Jul-20195.5 KiB215161

uuid.goH A D25-Jul-20196.8 KiB273191

README.md

1gocql
2=====
3
4[![Join the chat at https://gitter.im/gocql/gocql](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/gocql/gocql?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5[![Build Status](https://travis-ci.org/gocql/gocql.svg?branch=master)](https://travis-ci.org/gocql/gocql)
6[![GoDoc](https://godoc.org/github.com/gocql/gocql?status.svg)](https://godoc.org/github.com/gocql/gocql)
7
8Package gocql implements a fast and robust Cassandra client for the
9Go programming language.
10
11Project Website: https://gocql.github.io/<br>
12API documentation: https://godoc.org/github.com/gocql/gocql<br>
13Discussions: https://groups.google.com/forum/#!forum/gocql
14
15Supported Versions
16------------------
17
18The following matrix shows the versions of Go and Cassandra that are tested with the integration test suite as part of the CI build:
19
20Go/Cassandra | 2.1.x | 2.2.x | 3.x.x
21-------------| -------| ------| ---------
221.10 | yes | yes | yes
231.11 | yes | yes | yes
24
25Gocql 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.
26
27Sunsetting Model
28----------------
29
30In 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.
31
32Installation
33------------
34
35    go get github.com/gocql/gocql
36
37
38Features
39--------
40
41* Modern Cassandra client using the native transport
42* Automatic type conversions between Cassandra and Go
43  * Support for all common types including sets, lists and maps
44  * Custom types can implement a `Marshaler` and `Unmarshaler` interface
45  * Strict type conversions without any loss of precision
46  * Built-In support for UUIDs (version 1 and 4)
47* Support for logged, unlogged and counter batches
48* Cluster management
49  * Automatic reconnect on connection failures with exponential falloff
50  * Round robin distribution of queries to different hosts
51  * Round robin distribution of queries to different connections on a host
52  * Each connection can execute up to n concurrent queries (whereby n is the limit set by the protocol version the client chooses to use)
53  * Optional automatic discovery of nodes
54  * Policy based connection pool with token aware and round-robin policy implementations
55* Support for password authentication
56* Iteration over paged results with configurable page size
57* Support for TLS/SSL
58* Optional frame compression (using snappy)
59* Automatic query preparation
60* Support for query tracing
61* Support for Cassandra 2.1+ [binary protocol version 3](https://github.com/apache/cassandra/blob/trunk/doc/native_protocol_v3.spec)
62  * Support for up to 32768 streams
63  * Support for tuple types
64  * Support for client side timestamps by default
65  * Support for UDTs via a custom marshaller or struct tags
66* Support for Cassandra 3.0+ [binary protocol version 4](https://github.com/apache/cassandra/blob/trunk/doc/native_protocol_v4.spec)
67* An API to access the schema metadata of a given keyspace
68
69Performance
70-----------
71While the driver strives to be highly performant, there are cases where it is difficult to test and verify. The driver is built
72with maintainability and code readability in mind first and then performance and features, as such every now and then performance
73may degrade, if this occurs please report and issue and it will be looked at and remedied. The only time the driver copies data from
74its read buffer is when it Unmarshal's data into supplied types.
75
76Some tips for getting more performance from the driver:
77* Use the TokenAware policy
78* Use many goroutines when doing inserts, the driver is asynchronous but provides a synchronous API, it can execute many queries concurrently
79* Tune query page size
80* Reading data from the network to unmarshal will incur a large amount of allocations, this can adversely affect the garbage collector, tune `GOGC`
81* Close iterators after use to recycle byte buffers
82
83Important Default Keyspace Changes
84----------------------------------
85gocql no longer supports executing "use <keyspace>" statements to simplify the library. The user still has the
86ability to define the default keyspace for connections but now the keyspace can only be defined before a
87session is created. Queries can still access keyspaces by indicating the keyspace in the query:
88```sql
89SELECT * FROM example2.table;
90```
91
92Example of correct usage:
93```go
94	cluster := gocql.NewCluster("192.168.1.1", "192.168.1.2", "192.168.1.3")
95	cluster.Keyspace = "example"
96	...
97	session, err := cluster.CreateSession()
98
99```
100Example of incorrect usage:
101```go
102	cluster := gocql.NewCluster("192.168.1.1", "192.168.1.2", "192.168.1.3")
103	cluster.Keyspace = "example"
104	...
105	session, err := cluster.CreateSession()
106
107	if err = session.Query("use example2").Exec(); err != nil {
108		log.Fatal(err)
109	}
110```
111This will result in an err being returned from the session.Query line as the user is trying to execute a "use"
112statement.
113
114Example
115-------
116
117```go
118/* Before you execute the program, Launch `cqlsh` and execute:
119create keyspace example with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
120create table example.tweet(timeline text, id UUID, text text, PRIMARY KEY(id));
121create index on example.tweet(timeline);
122*/
123package main
124
125import (
126	"fmt"
127	"log"
128
129	"github.com/gocql/gocql"
130)
131
132func main() {
133	// connect to the cluster
134	cluster := gocql.NewCluster("192.168.1.1", "192.168.1.2", "192.168.1.3")
135	cluster.Keyspace = "example"
136	cluster.Consistency = gocql.Quorum
137	session, _ := cluster.CreateSession()
138	defer session.Close()
139
140	// insert a tweet
141	if err := session.Query(`INSERT INTO tweet (timeline, id, text) VALUES (?, ?, ?)`,
142		"me", gocql.TimeUUID(), "hello world").Exec(); err != nil {
143		log.Fatal(err)
144	}
145
146	var id gocql.UUID
147	var text string
148
149	/* Search for a specific set of records whose 'timeline' column matches
150	 * the value 'me'. The secondary index that we created earlier will be
151	 * used for optimizing the search */
152	if err := session.Query(`SELECT id, text FROM tweet WHERE timeline = ? LIMIT 1`,
153		"me").Consistency(gocql.One).Scan(&id, &text); err != nil {
154		log.Fatal(err)
155	}
156	fmt.Println("Tweet:", id, text)
157
158	// list all tweets
159	iter := session.Query(`SELECT id, text FROM tweet WHERE timeline = ?`, "me").Iter()
160	for iter.Scan(&id, &text) {
161		fmt.Println("Tweet:", id, text)
162	}
163	if err := iter.Close(); err != nil {
164		log.Fatal(err)
165	}
166}
167```
168
169Data Binding
170------------
171
172There are various ways to bind application level data structures to CQL statements:
173
174* You can write the data binding by hand, as outlined in the Tweet example. This provides you with the greatest flexibility, but it does mean that you need to keep your application code in sync with your Cassandra schema.
175* You can dynamically marshal an entire query result into an `[]map[string]interface{}` using the `SliceMap()` API. This returns a slice of row maps keyed by CQL column names. 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.
176* As a refinement on the `SliceMap()` API you can also call `MapScan()` which returns `map[string]interface{}` instances in a row by row fashion.
177* The `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.
178* The [gocqlx](https://github.com/scylladb/gocqlx) package is an idiomatic extension to gocql that provides usability features. With gocqlx you can bind the query parameters from maps and structs, use named query parameters (:identifier) and scan the query results into structs and slices. It comes with a fluent and flexible CQL query builder that supports full CQL spec, including BATCH statements and custom functions.
179* Building on top of the gocql driver, [cqlr](https://github.com/relops/cqlr) adds the ability to auto-bind a CQL iterator to a struct or to bind a struct to an INSERT statement.
180* Another external project that layers on top of gocql is [cqlc](http://relops.com/cqlc) which generates gocql compliant code from your Cassandra schema so that you can write type safe CQL statements in Go with a natural query syntax.
181* [gocassa](https://github.com/hailocab/gocassa) is an external project that layers on top of gocql to provide convenient query building and data binding.
182* [gocqltable](https://github.com/kristoiv/gocqltable) provides an ORM-style convenience layer to make CRUD operations with gocql easier.
183
184Ecosystem
185---------
186
187The following community maintained tools are known to integrate with gocql:
188
189* [gocqlx](https://github.com/scylladb/gocqlx) is a gocql extension that automates data binding, adds named queries support, provides flexible query builders and plays well with gocql.
190* [journey](https://github.com/db-journey/journey) is a migration tool with Cassandra support.
191* [negronicql](https://github.com/mikebthun/negronicql) is gocql middleware for Negroni.
192* [cqlr](https://github.com/relops/cqlr) adds the ability to auto-bind a CQL iterator to a struct or to bind a struct to an INSERT statement.
193* [cqlc](http://relops.com/cqlc) generates gocql compliant code from your Cassandra schema so that you can write type safe CQL statements in Go with a natural query syntax.
194* [gocassa](https://github.com/hailocab/gocassa) provides query building, adds data binding, and provides easy-to-use "recipe" tables for common query use-cases.
195* [gocqltable](https://github.com/kristoiv/gocqltable) is a wrapper around gocql that aims to simplify common operations.
196* [gockle](https://github.com/willfaught/gockle) provides simple, mockable interfaces that wrap gocql types
197* [scylladb](https://github.com/scylladb/scylla) is a fast Apache Cassandra-compatible NoSQL database
198* [go-cql-driver](https://github.com/MichaelS11/go-cql-driver) is an CQL driver conforming to the built-in database/sql interface. It is good for simple use cases where the database/sql interface is wanted. The CQL driver is a wrapper around this project.
199
200Other Projects
201--------------
202
203* [gocqldriver](https://github.com/tux21b/gocqldriver) is the predecessor of gocql based on Go's `database/sql` package. This project isn't maintained anymore, because Cassandra wasn't a good fit for the traditional `database/sql` API. Use this package instead.
204
205SEO
206---
207
208For 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.
209
210License
211-------
212
213> Copyright (c) 2012-2016 The gocql Authors. All rights reserved.
214> Use of this source code is governed by a BSD-style
215> license that can be found in the LICENSE file.
216