entc/gen: add support for helper templates

Closed #1655
This commit is contained in:
Ariel Mashraki
2021-07-19 15:33:35 +03:00
committed by Ariel Mashraki
parent dd4d2521a7
commit 81eeefa6a2
3 changed files with 63 additions and 12 deletions

View File

@@ -0,0 +1,21 @@
{{/*
Copyright 2019-present Facebook Inc. All rights reserved.
This source code is licensed under the Apache 2.0 license found
in the LICENSE file in the root directory of this source tree.
*/}}
{{/* The line below tells Intellij/GoLand to enable the autocompletion based *gen.Graph type. */}}
{{/* gotype: entgo.io/ent/entc/gen.Graph */}}
{{ define "helper/one" }}
{{ range $n := $.Nodes }}
{{/* Non empty global helper template. */}}
{{ end }}
{{ end }}
{{ define "helper/two" }}
{{ range $n := $.Nodes }}
{{/* Non empty global helper template. */}}
{{ end }}
{{ end }}

View File

@@ -164,6 +164,17 @@ func (t *tables) Load(ctx context.Context, querier querier) ([]string, error) {
return tables, err
}
{{ template "node/helper/loadtable" $ }}
{{ end }}
{{ define "client/fields/additional" }}
// additional fields for node api
tables tables
{{ end }}
{{/* An example of a local helper template. */}}
{{ define "node/helper/loadtable" }}
func (tables) load(ctx context.Context, querier querier) ([]string, error) {
rows := &sql.Rows{}
query, args := sql.Select("type").
@@ -177,9 +188,4 @@ func (tables) load(ctx context.Context, querier querier) ([]string, error) {
var tables []string
return tables, sql.ScanSlice(rows, &tables)
}
{{ end }}
{{ define "client/fields/additional" }}
// additional fields for node api
tables tables
{{ end }}
{{ end }}