entc/gen/template: add extend-templates for all builders (#1364)

This commit is contained in:
Ariel Mashraki
2021-03-20 21:46:15 +02:00
committed by GitHub
parent c84350a43a
commit 970887b4d0
6 changed files with 42 additions and 8 deletions

File diff suppressed because one or more lines are too long

View File

@@ -159,6 +159,8 @@ var (
// patterns for extending partial-templates (included by other templates).
partialPatterns = [...]string{
"config/*/*",
"create/additional/*",
"delete/additional/*",
"dialect/*/*/*/spec/*",
"dialect/*/*/spec/*",
"dialect/*/config/*/*",
@@ -173,6 +175,8 @@ var (
"import/additional/*",
"model/additional/*",
"model/comment/additional/*",
"update/additional/*",
"query/additional/*",
}
// templates holds the Go templates for the code generation.
templates *Template

View File

@@ -130,6 +130,13 @@ func ({{ $receiver }} *{{ $builder }}) check() error {
{{ xtemplate $tmpl . }}
{{ end }}
{{- /* Support adding create methods by global templates. */}}
{{- with $tmpls := matchTemplate "create/additional/*" }}
{{- range $tmpl := $tmpls }}
{{ xtemplate $tmpl $ }}
{{- end }}
{{- end }}
{{ $bulk := printf "%sCreateBulk" (pascal $.Name) }}
{{ $receiver = receiver $bulk }}

View File

@@ -75,6 +75,13 @@ func ({{ $receiver }} *{{ $builder }}) ExecX(ctx context.Context) int {
{{ xtemplate $tmpl . }}
{{ end }}
{{- /* Support adding delete methods by global templates. */}}
{{- with $tmpls := matchTemplate "delete/additional/*" }}
{{- range $tmpl := $tmpls }}
{{ xtemplate $tmpl $ }}
{{- end }}
{{- end }}
{{ $onebuilder := $.DeleteOneName }}
{{ $oneReceiver := receiver $onebuilder }}

View File

@@ -378,6 +378,15 @@ func ({{ $receiver }} *{{ $builder }}) prepareQuery(ctx context.Context) error {
{{ xtemplate $tmpl . }}
{{ end }}
{{- /* Support adding query methods by global templates. In order to generate dialect-sepcific methods,
prefix this template with "dialect/{{ .Storage }}". For example: "dialect/sql/query/additional/*". */}}
{{- with $tmpls := matchTemplate "query/additional/*" }}
{{- range $tmpl := $tmpls }}
{{ xtemplate $tmpl $ }}
{{- end }}
{{- end }}
{{/* groupby builder */}}
{{ $groupReceiver := receiver $groupBuilder }}

View File

@@ -214,6 +214,13 @@ func ({{ $receiver }} *{{ $onebuilder }}) ExecX(ctx context.Context) {
{{ xtemplate $tmpl . }}
{{ end }}
{{- /* Support adding update methods by global templates. */}}
{{- with $tmpls := matchTemplate "update/additional/*" }}
{{- range $tmpl := $tmpls }}
{{ xtemplate $tmpl $ }}
{{- end }}
{{- end }}
{{ end }}
{{/* shared struct fields between the two updaters */}}