Skip to content

Commit

Permalink
gen/entc/template: add option to process nodes after query using exte…
Browse files Browse the repository at this point in the history
…rnal templates (ent#2444)
  • Loading branch information
a8m authored and gitlawr committed Apr 13, 2022
1 parent 591f1d6 commit 7e19b4f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions entc/gen/template.go
Expand Up @@ -188,6 +188,7 @@ var (
"dialect/sql/select/additional/*",
"dialect/sql/predicate/edge/*/*",
"dialect/sql/query/additional/*",
"dialect/sql/query/all/nodes/*",
"dialect/sql/query/from/*",
"dialect/sql/query/path/*",
"import/additional/*",
Expand Down
8 changes: 7 additions & 1 deletion entc/gen/template/dialect/sql/query.tmpl
Expand Up @@ -79,12 +79,18 @@ func ({{ $receiver }} *{{ $builder }}) sqlAll(ctx context.Context, hooks ...quer
{{ template "dialect/sql/query/eagerloading" . }}
{{- end }}
{{- end }}
{{- /* Allow extensions to inject code using templates to process nodes before they are returned. */}}
{{- with $tmpls := matchTemplate "dialect/sql/query/all/nodes/*" }}
{{- range $tmpl := $tmpls }}
{{- xtemplate $tmpl $ }}
{{- end }}
{{- end }}
return nodes, nil
}

func ({{ $receiver }} *{{ $builder }}) sqlCount(ctx context.Context) (int, error) {
_spec := {{ $receiver }}.querySpec()
{{- /* Allow mutating the sqlgraph.QuerySpec by ent extensions or user templates.*/}}
{{- /* Allow mutating the sqlgraph.QuerySpec by ent extensions or user templates. */}}
{{- with $tmpls := matchTemplate "dialect/sql/query/spec/*" }}
{{- range $tmpl := $tmpls }}
{{- xtemplate $tmpl $ }}
Expand Down

0 comments on commit 7e19b4f

Please sign in to comment.