Code generation for structs for tables

This commit is contained in:
Pavle Kosutic
2021-12-10 09:19:47 +01:00
committed by Michal Jan Matczuk
parent 3e151149a0
commit 2942397ab6
5 changed files with 149 additions and 5 deletions

View File

@@ -2,7 +2,12 @@
package {{.PackageName}}
import "github.com/scylladb/gocqlx/v2/table"
import (
"github.com/scylladb/gocqlx/v2/table"
{{- range .Imports}}
"{{.}}"
{{- end}}
)
// Table models.
var (
@@ -30,3 +35,27 @@ var (
{{end}}
{{end}}
)
{{with .UserTypes}}
{{range .}}
{{- $type_name := .Name | camelize}}
{{- $field_types := .FieldTypes}}
type {{$type_name}}Type struct {
{{- range $index, $element := .FieldNames}}
{{- $type := index $field_types $index}}
{{. | camelize}} {{getNativeTypeSting $type | mapScyllaToGoType}}
{{- end}}
}
{{- end}}
{{- end}}
{{with .Tables}}
{{range .}}
{{- $model_name := .Name | camelize}}
type {{$model_name}}Struct struct {
{{- range .Columns}}
{{.Name | camelize}} {{.Validator | mapScyllaToGoType}}
{{- end}}
}
{{- end}}
{{- end}}