snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
This commit is contained in:
18
entc/integration/ent/template/client.tmpl
Normal file
18
entc/integration/ent/template/client.tmpl
Normal file
@@ -0,0 +1,18 @@
|
||||
{{/*
|
||||
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.
|
||||
*/}}
|
||||
|
||||
{{ define "client/additional/driver/dialect" }}
|
||||
// Dialect returns the driver dialect.
|
||||
func(c *Client) Dialect() string {
|
||||
return c.driver.Dialect()
|
||||
}
|
||||
|
||||
// Driver returns the underlying driver.
|
||||
func(c *Client) Driver() dialect.Driver {
|
||||
return c.driver
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
14
entc/integration/ent/template/ext.go
Normal file
14
entc/integration/ent/template/ext.go
Normal file
@@ -0,0 +1,14 @@
|
||||
// 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.
|
||||
|
||||
package template
|
||||
|
||||
// Extension is a template extension.
|
||||
type Extension struct {
|
||||
Type string
|
||||
}
|
||||
|
||||
func (*Extension) Name() string {
|
||||
return "Extension"
|
||||
}
|
||||
33
entc/integration/ent/template/ext.tmpl
Normal file
33
entc/integration/ent/template/ext.tmpl
Normal file
@@ -0,0 +1,33 @@
|
||||
{{/*
|
||||
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.
|
||||
*/}}
|
||||
|
||||
{{ define "extension" }}
|
||||
{{ $pkg := base $.Config.Package }}
|
||||
{{ template "header" $ }}
|
||||
|
||||
{{ range $n := $.Nodes }}
|
||||
{{ $hasExt := false }}
|
||||
{{ range $f := $n.Fields }}{{ if $f.Annotations.Extension }}{{ $hasExt = true }}{{ end }}{{ end }}
|
||||
{{ range $e := $n.Edges }}{{ if $e.Annotations.Extension }}{{ $hasExt = true }}{{ end }}{{ end }}
|
||||
{{/* If one or fields contain the "Extension" annotation */}}
|
||||
{{ if $hasExt }}
|
||||
// {{ $n.Name }}Extension is a type for holding the extension information defined in the schema.
|
||||
type {{ $n.Name }}Extension struct {
|
||||
{{- range $f := $n.Fields }}
|
||||
{{- with $ant := $f.Annotations.Extension }}
|
||||
{{ $f.StructField }} {{ $ant.Type }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- range $e := $n.Edges }}
|
||||
{{- with $ant := $e.Annotations.Extension }}
|
||||
{{ $e.StructField }} {{ $ant.Type }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ end }}
|
||||
12
entc/integration/ent/template/fields.tmpl
Normal file
12
entc/integration/ent/template/fields.tmpl
Normal file
@@ -0,0 +1,12 @@
|
||||
{{/* A template for adding additional fields to specific types. */}}
|
||||
{{ define "model/fields/additional" }}
|
||||
{{- /* Add static fields to the "Card" entity. */}}
|
||||
{{- if eq $.Name "Card" }}
|
||||
// StaticField defined by templates.
|
||||
StaticField string `json:"boring,omitempty"`
|
||||
{{- end }}
|
||||
{{ end }}
|
||||
|
||||
{{ define "client/fields/additional/node" }}
|
||||
TemplateField struct{}
|
||||
{{ end }}
|
||||
25
entc/integration/ent/template/meta.tmpl
Normal file
25
entc/integration/ent/template/meta.tmpl
Normal file
@@ -0,0 +1,25 @@
|
||||
{{/*
|
||||
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.
|
||||
*/}}
|
||||
|
||||
{{/* A template for adding additional fields to specific types. */}}
|
||||
{{ define "meta/additional/enums" }}
|
||||
{{- range $f := $.EnumFields }}
|
||||
{{- if not $f.HasGoType }}
|
||||
{{ $enum := trimPackage $f.Type.String $.Package }}
|
||||
{{ $receiver := receiver $f.BuilderField }}
|
||||
|
||||
// Ptr returns a new pointer to the enum value.
|
||||
func ({{ $receiver }} {{ $enum }}) Ptr() *{{ $enum }} {
|
||||
return &{{ $receiver }}
|
||||
}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{ end }}
|
||||
|
||||
|
||||
{{ define "meta/additional/random" }}
|
||||
// comment from another template.
|
||||
{{ end }}
|
||||
Reference in New Issue
Block a user