scylladb/gocqlx

Documentation: skipped meta-data conversion

Closed this issue · 2 comments

In the initial documentation, there is no mention of fields needing to be exportable to be used with the default mapper.

// 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 camel case by default, no need to add special tags.
// If you want to disable a field add `db:"-"` tag, it will not be persisted.
type Person struct {
	FirstName string
	LastName  string
	Email     []string
}

Can clarification be added that only exported fields will be mapped by the default mapper in the section above?

I lost a significant amount of time (and ended up debugging into the library) to determine that I needed to uppercase my (otherwise package internal) field names so the default mapper worked. Especially with the db:""` comment that is already there, I erroneously thought that was the way to skip fields, not also via exportablity.

The best would be document that and also document how to work with not exported fields.
Please send a PR.

Thanks.