forked from dizzyfool/genna
/
template.go
50 lines (44 loc) · 1.39 KB
/
template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package model
const Template = `//nolint
//lint:file-ignore U1000 ignore unused code, it's generated
package {{.Package}}{{if .HasImports}}
import ({{range .Imports}}
"{{.}}"{{end}}
){{end}}
var Columns = struct { {{range .Entities}}
{{.GoName}} struct{
{{range $i, $e := .Columns}}{{if $i}}, {{end}}{{.GoName}}{{end}} string{{if .HasRelations}}
{{range $i, $e := .Relations}}{{if $i}}, {{end}}{{.GoName}}{{end}} string{{end}}
}{{end}}
}{ {{range .Entities}}
{{.GoName}}: struct {
{{range $i, $e := .Columns}}{{if $i}}, {{end}}{{.GoName}}{{end}} string{{if .HasRelations}}
{{range $i, $e := .Relations}}{{if $i}}, {{end}}{{.GoName}}{{end}} string{{end}}
}{ {{range .Columns}}
{{.GoName}}: "{{.PGName}}",{{end}}{{if .HasRelations}}
{{range .Relations}}
{{.GoName}}: "{{.GoName}}",{{end}}{{end}}
},{{end}}
}
var Tables = struct { {{range .Entities}}
{{.GoName}} struct {
Name{{if not .NoAlias }}, Alias{{end}} string
}{{end}}
}{ {{range .Entities}}
{{.GoName}}: struct {
Name{{if not .NoAlias}}, Alias{{end}} string
}{
Name: "{{.PGFullName}}"{{if not .NoAlias}},
Alias: "{{.Alias}}",{{end}}
},{{end}}
}
{{range $model := .Entities}}
type {{.GoName}} struct {
tableName struct{} {{.Tag}}
{{range .Columns}}
{{.GoName}} {{.Type}} {{.Tag}} {{.Comment}}{{end}}{{if .HasRelations}}
{{range .Relations}}
{{.GoName}} *{{.GoType}} {{.Tag}} {{.Comment}}{{end}}{{end}}
}
{{end}}
`