v2.0
Lightweight Transactions (aka CAS)
Requires Scylla 4.0 or Scylla 3.3 with --experimental flag enabled.
The "Get" function variant is added: GetCAS
, GetCASRelease
, these functions returns the "applied" indicator. Similarly there are ExecCAS
, ExecCASRelease
functions if you are not interested in preimage. See a lock example in example_test.go.
User Defined Types Automation
You can now add UDT trait to a type by adding a single line of code:
type Coordinates struct {
gocqlx.UDT
X int
Y int
}
You can also add UDT trait to an alien type by embedding a pointer to it:
type CoordinatesUDT struct {
gocqlx.UDT
*coordinates
}
See the full runnable examples in example_test.go.
New Session API
Instead of (old format):
gocqlx.Query(session.Query(`SELECT * FROM struct_table`), nil).Get(&v)
we can now use session "Query" function to return Queryx instance:
session.Query(`SELECT * FROM struct_table`, nil).Get(&v)
It requires wrapping the session on creation:
// Create gocql cluster.
cluster := gocql.NewCluster(hosts...)
// Wrap session on creation, gocqlx session embeds gocql.Session pointer.
session, err := gocqlx.WrapSession(cluster.CreateSession())
if err != nil {
t.Fatal(err)
}
User Defined Types are Scanable
Types implementing UDT marshalling functions are now "scanable", which means you can use them in "Get" and "Select" function families, for queries that return a single column. StructOnly modifier was added to Iterx. When enabled you can use the UDT enabled types as normal structs.
API incompatibilities
Iter(q *gocql.Query) *Iterx
constructor is removed, one should use Queryx::Iter instead
API- Migrate package uses now gocqlx.Session in place of *gocql.Session
Deprecated APIs
Query(q *gocql.Query, names []string) *Queryx
constructor is deprecated, one should use the new Session- qb Batch is deprecated