mirror of
https://github.com/ent/ent.git
synced 2026-05-28 09:49:08 +03:00
entc/gen/template: add extend-templates for all builders (#1364)
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -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
|
||||
|
||||
@@ -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 }}
|
||||
|
||||
|
||||
@@ -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 }}
|
||||
|
||||
|
||||
@@ -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 }}
|
||||
|
||||
@@ -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 */}}
|
||||
|
||||
Reference in New Issue
Block a user