scylladb/gocqlx

Can’t update UDT using gocqlx

Closed this issue · 2 comments

Hi so I have a usecase in which a user can create a secondary index on any table by calling an API. And I’m recording these indexes in a common table using map<text, frozen> where indexes is a User Defined Type:

CREATE TYPE indexes (
    local BOOLEAN,
    index_name TEXT,
    table_name TEXT,
    columns SET<TEXT>
);

When the API is called the secondary index is created. This part is working fine. But updating the row in the common tables is not. All the data in the UDT is stored as null:

 {'table_table1_20e24b85_d425_11e_int13_idx': {local: null, name: null, table_name: null, columns: null}}

Here’s my gocqlx code:

selectedTable.Indexes[indexName] = models.IndexModel{
	Local:     reqBody.Local,
	Name:      indexName,
	TableName: selectedTable.InternalName,
	Columns:   reqBody.Columns,
}

stmt, names = qb.Update("tables").Set("indexes").
	Where(qb.Eq("internal_name"), qb.Eq("name"), qb.Eq("description")).ToCql()
if err := config.GetScylla().Query(stmt, names).BindStruct(&selectedTable).ExecRelease(); err != nil {
	utils.HandleErrorResponse(c, err)
	return
}

I hope the code is self-explanatory enough but all I’m doing is creating a map of string->indexes(UDT) to put in the common table and updating the common table with it.

Side note: why is the documentation on gocqlx so bad?

Experiencing the same issue 2.8.
Adding gocqlx.UDT to the UDT struct does not solve the issue. Need to add cql: struct tags and it will work.

type MyStruct struct {
	// gocqlx.UDT
	foo     string `cql:"foo"`
	bar     string `cql:"bar"`
}