Gocqlx Versions Save

All-In-One: CQL query builder, ORM and migration tool

v2.8.0

1 year ago

The release adds support for schemagen to generate structs in table model, as well as username/password authentication to schemagen.

What's Changed

New Contributors

Full Changelog: https://github.com/scylladb/gocqlx/compare/v2.7.0...v2.8.0

v2.7.0

2 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/scylladb/gocqlx/compare/v2.6.0...v2.7.0

v2.6.0

2 years ago

This release adds automatic support for gocql.UnsetValue. This is a special value representing not set i.e. not resulting in any change to the existing value. This is great for PATCHING entities, you can have a single prepared statement that can be reused to update any combination of the fields.

Example:

The following example upserts Operation not changing the Fee field.

	// Insert operation with empty fee.
	insertQuery = insertOperation.Query(session).
		WithBindTransformer(gocqlx.UnsetEmptyTransformer).
		BindStruct(Operation{
			ID:        "2",
			ClientID:  "42",
			Type:      "Input",
			PaymentID: "1",
			Fee:       nil,
		})
	if err := insertQuery.ExecRelease(); err != nil {
		t.Fatal("ExecRelease() failed:", err)
	}

Also, the bind transformer can be set globally for the whole application.

	// Set default transformer to avoid setting it for each query.
	gocqlx.DefaultBindTransformer = gocqlx.UnsetEmptyTransformer

What's Changed

New Contributors

Full Changelog: https://github.com/scylladb/gocqlx/compare/v2.5.0...v2.6.0

v2.5.0

2 years ago

Schemagen :1st_place_medal:

This release adds schemagen tool that generates goclqx table models based on database schema.

Example:

Running the following command for examples keyspace:

$GOBIN/schemagen -cluster="127.0.0.1:9042" -keyspace="examples" -output="models" -pkgname="models"

Generates models/models.go as follows:

// Code generated by "gocqlx/cmd/schemagen"; DO NOT EDIT.

package models

import "github.com/scylladb/gocqlx/v2/table"

// Table models.
var (
	Playlists = table.New(table.Metadata{
		Name: "playlists",
		Columns: []string{
			"album",
			"artist",
			"id",
			"song_id",
			"title",
		},
		PartKey: []string{
			"id",
		},
		SortKey: []string{
			"title",
			"album",
			"artist",
		},
	})

	Songs = table.New(table.Metadata{
		Name: "songs",
		Columns: []string{
			"album",
			"artist",
			"data",
			"id",
			"tags",
			"title",
		},
		PartKey: []string{
			"id",
		},
		SortKey: []string{},
	})
)

Installation

go get -u "github.com/scylladb/gocqlx/v2/cmd/schemagen"

What's Changed

New Contributors

Full Changelog: https://github.com/scylladb/gocqlx/compare/v2.4.0...v2.5.0

v2.4.0

3 years ago

This release adds support for embedding migration files inside binary with go:embed. It requires go 1.16+.

Example:

Embed all cql files in your migration directory.

//go:embed *.cql
var Files embed.FS

Pass the FS to migration function.

if err := migrate.FromFS(context.Background(), session, cql.Files); err != nil {
	// handle error
}

The migrate.Migrate function is now deprecated.

v2.3.0

3 years ago

This release:

  • Adds dbutil packages that will contain auxiliary tools built on top of gocqlx and its sub packages
  • Adds dbutil.RewriteTable a generalization of table.RewriteRows that can clone a table and apply a data transformation for each row
  • Adds migrate.CallbackRegister to simplify usage of migration callback
  • Adds support for in CQL file callbacks with a CQL comment -- CALL MyCallbackName;
INSERT INTO bar (id) VALUES (1);

-- CALL MyCallbackName;

INSERT INTO bar (id) VALUES (2);

See the complete example in migrate/example dir.

v2.2.0

3 years ago

This release:

  • Adds InsertBuilder and SelectAll functions to table module
  • Adds RewriteRows function to table module, it sequentially rewrites all data in a table, this is useful for updating TTLs on small or medium sized tables
  • Migrates CI from Travis to GH actions

v2.1.0

3 years ago

This release adds Query and QueryContext functions to query builder and table modules. It simplifies query creation, instead of

	stmt, names := qb.Select("cluster").Columns("id").ToCql()
	q := gocqlx.Query(session.Query(stmt), names)

one can now write

	q := qb.Select("cluster").Columns("id").Query(session)

v2.0.3

3 years ago

This release adds NewSession function for easier integration with codebases using *gocql.Session.

v2.0.2

4 years ago