Schemagen
schemagen is a command-line tool that introspects your ScyllaDB keyspace and generates Go struct definitions and table.Metadata models automatically.
Usage
schemagen -cluster="127.0.0.1" -keyspace="my_keyspace" -output="models" -pkgname="models"
Flags
-cluster: Comma-separated list of host:port tuples (default "127.0.0.1").-keyspace: Keyspace to inspect (required).-output: Folder path to output the generated file (default "models").-pkgname: Package name for the generated file (default "models").-ignore-names: Comma-separated list of table/view/index names to skip.
Generated Output
The tool generates a Go file containing:
- Structs: Go structs representing your tables, views, and UDTs, with fields mapped to columns.
- Table Models: Pre-configured
table.Metadatavariables for use with thetablepackage.
Example Output:
package models
import "github.com/scylladb/gocqlx/v3/table"
var Users = table.New(table.Metadata{
Name: "users",
Columns: []string{"id", "email", "name"},
PartKey: []string{"id"},
SortKey: []string{},
})
type UsersStruct struct {
Id [16]byte
Email string
Name string
}