cmd/schemagen: refactoring

- Replace log.Faltal with error wrapping in schemagen func
- Simplify tests, use temp dir and ioutil functions, remove boilerplate code
- In test use schemagen keyspace to avoid name conflict with examples
- Change template
This commit is contained in:
Michał Matczuk
2021-11-17 11:49:42 +01:00
committed by Michal Jan Matczuk
parent 39bf42f122
commit 8477485a45
7 changed files with 239 additions and 288 deletions

View File

@@ -4,27 +4,29 @@ package {{.PackageName}}
import "github.com/scylladb/gocqlx/v2/table"
// Table models.
var (
{{with .Tables}}
{{range .}}
{{$model_name := .Name | camelize}}
var {{$model_name}}Metadata = table.Metadata {
Name: "{{.Name}}",
Columns: []string{
{{- range .OrderedColumns}}
"{{.}}",
{{- end}}
},
PartKey: []string {
{{- range .PartitionKey}}
"{{.Name}}",
{{- end}}
},
SortKey: []string{
{{- range .ClusteringColumns}}
"{{.Name}}",
{{- end}}
},
}
var {{$model_name}}Table = table.New({{$model_name}}Metadata)
{{end}}
{{end}}
{{range .}}
{{$model_name := .Name | camelize}}
{{$model_name}} = table.New(table.Metadata {
Name: "{{.Name}}",
Columns: []string{
{{- range .OrderedColumns}}
"{{.}}",
{{- end}}
},
PartKey: []string {
{{- range .PartitionKey}}
"{{.Name}}",
{{- end}}
},
SortKey: []string{
{{- range .ClusteringColumns}}
"{{.Name}}",
{{- end}}
},
})
{{end}}
{{end}}
)