scylladb/gocqlx sits at 1.0k stars on GitHub, written primarily in Go. All-In-One: CQL query builder, ORM and migration tool
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
GocqlX makes working with Scylla easy and less error-prone.
It’s inspired by Sqlx, a tool for working with SQL databases, but it goes beyond what Sqlx provides.
Compatibility
Versions of GocqlX prior to v3.0.0 are compatible with both Apache Cassandra’s gocql and ScyllaDB’s fork.
However, starting with v3.0.0, GocqlX exclusively supports the scylladb/gocql driver.
This version supports scylladb/gocql v1.20.0 or newer.
The protocol v5 query and batch APIs are available in v1.19.0; v1.20.0 is the supported minimum by policy and the version used for testing.
Add a replace directive to your application's go.mod:
// Use the latest version of scylladb/gocql; check for updates at https://github.com/scylladb/gocql/releases
replace github.com/gocql/gocql => github.com/scylladb/gocql v1.20.0
Replace directives in dependencies are not inherited.
Update any older driver replacement in your application's go.mod before upgrading GocqlX.
This is required because GocqlX relies on ScyllaDB-specific extensions and bug fixes introduced in the gocql fork. Attempting to use the standard gocql driver with GocqlX v3.0.0+ may lead to build or runtime issues.
Features
Binding query parameters from struct fields, map, or both
Scanning query results into structs based on field names
Convenient functions for common tasks such as loading a single row into a struct or all rows into a slice (list) of structs
Making any struct a UDT without implementing marshalling functions
GocqlX is fast. Its performance is comparable to raw driver. You can find some benchmarks here.
Subpackages provide additional functionality:
CQL query builder (package qb)
CRUD operations based on table model (package table)
Database migrations (package migrate)
Installation GocqlX
Add GocqlX to your Go module:
go get github.com/scylladb/gocqlx/v3
Installation schemagen
Unfortunately you can't install it via go install, since go.mod contains replace directive.
So, you have to check it out and install manually:
git clone [email protected]:scylladb/gocqlx.git
cd gocqlx/cmd/schemagen/
go install .
// metadata specifies table name and columns it must be in sync with schema.
var personMetadata = table.Metadata{
Name: "person",
Columns: []string{"first_name", "last_name", "email"},
PartKey: []string{"first_name"},
SortKey: []string{"last_name"},
}
// personTable allows for simple CRUD operations based on personMetadata.
var personTable = table.New(personMetadata)
// Person represents a row in person table.
// Field names are converted to snake case by default, no need to add special tags.
// A field will not be persisted by adding the `db:"-"` tag or making it unexported.
type Person struct {
FirstName string
LastName string
Email []string
HairColor string `db:"-"` // exported and skipped
eyeColor string // unexported also skipped
}
Bind data from a struct and insert a row:
p := Person{
"Michał",
"Matczuk",
[]string{"[email protected]"},
"red", // not persisted
"hazel" // not persisted
}
q := session.Query(personTable.Insert()).BindStruct(p)
if err := q.ExecRelease(); err != nil {
log.Fatal(err)
}
Load a single row to a struct:
p := Person{
"Michał",
"Matczuk",
nil, // no email
}
q := session.Query(personTable.Get()).BindStruct(p)
if err := q.GetRelease(&p); err != nil {
log.Fatal(err)
}
fmt.Println(p)
// stdout: {Michał Matczuk [[email protected]]}
Load all rows in to a slice:
var people []Person
q := session.Query(personTable.Select()).BindMap(qb.M{"first_name": "Michał"})
if err := q.SelectRelease(&people); err != nil {
log.Fatal(err)
}
fmt.Println(people)
// stdout: [{Michał Matczuk [[email protected]]}]
Generating table metadata with schemagen
Installation
go get -u "github.com/scylladb/gocqlx/v3/cmd/schemagen"
Usage:
schemagen [flags]
Flags:
-cluster string
a comma-separated list of host:port tuples (default "127.0.0.1")
-keyspace string
keyspace to inspect (required)
-output string
the name of the folder to output to (default "models")
-pkgname string
the name you wish to assign to your generated package (default "models")
Example:
Running the following command for examples keyspace:
You can find lots of examples in example_test.go.
There is also a runnable example app with its own go.mod in examples/basic.
Go and run them locally:
make run-scylla
make run-examples
Training
The course Using Scylla Drivers in Scylla University explains how to use drivers in different languages to interact with a Scylla cluster. The lesson, Golang and Scylla Part 3 - GoCQLX, goes over a sample application that, using GoCQLX, interacts with a three-node Scylla cluster. It connects to a Scylla cluster, displays the contents of a table, inserts and deletes data, and shows the contents of the table after each action. Scylla University includes other training material and online courses which will help you become a Scylla NoSQL database expert.
Performance
GocqlX performance is comparable to the raw gocql driver.
Below benchmark results running on my laptop.
This project is distributed under the Apache 2.0 license. See the LICENSE file for details.
It contains software from:
gocql project, licensed under the BSD license
sqlx project, licensed under the MIT license
Apache®, Apache Cassandra® are either registered trademarks or trademarks of
the Apache Software Foundation in the United States and/or other countries.
No endorsement by The Apache Software Foundation is implied by the use of these marks.
No homepage URL was recorded for scylladb/gocqlx in TopGit's last sync. The README tab above frequently contains screenshots and demo links, or check the repository description on GitHub.
How active is development on scylladb/gocqlx?
The most recent commit recorded on scylladb/gocqlx was 2 days ago, based on the GitHub push timestamp. The repository has 133 forks — one of the better signals of community interest.
Is scylladb/gocqlx open source?
Yes — scylladb/gocqlx ships under the Apache-2.0 license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/scylladb/gocqlx.
What license does scylladb/gocqlx use?
scylladb/gocqlx is released under the Apache-2.0 license. Always verify the LICENSE file directly on GitHub for the authoritative terms — license strings can be edited out of sync with a project's actual stance.
What topics is scylladb/gocqlx associated with?
GitHub's repository topics for scylladb/gocqlx: "cassandra", "cql", "gocql", "golang", "migration", "orm", "query-builder", "scylla". TopGit's editorial category is Backend.
Where do I read more about scylladb/gocqlx?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/scylladb/gocqlx is the definitive source.
Read full README in the tab above.
Still deciding about gocqlx?
One click hands the question to an AI along with this page — see what it says about gocqlx.