snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
This commit is contained in:
37
examples/entcpkg/ent/template/debug.tmpl
Normal file
37
examples/entcpkg/ent/template/debug.tmpl
Normal file
@@ -0,0 +1,37 @@
|
||||
{{ define "debug" }}
|
||||
|
||||
{{/* The line below tells Intellij/GoLand to enable the autocompletion based *gen.Graph type. */}}
|
||||
{{/* gotype: entgo.io/ent/entc/gen.Graph */}}
|
||||
|
||||
{{/* A template that will be generated to a file named "debug.go" and
|
||||
add the functionality for running each client <T> in debug mode. */}}
|
||||
|
||||
{{/* Add the base header for the generated file. */}}
|
||||
{{ $pkg := base $.Config.Package }}
|
||||
{{ template "header" $ }}
|
||||
|
||||
{{/* Loop over all nodes and add option the "Debug()" method. */}}
|
||||
{{ range $n := $.Nodes }}
|
||||
{{ $client := print $n.Name "Client" }}
|
||||
func (c *{{ $client }}) Debug() *{{ $client }} {
|
||||
if c.debug {
|
||||
return c
|
||||
}
|
||||
cfg := config{driver: dialect.Debug(c.driver, c.log), log: c.log, debug: true, hooks: c.hooks}
|
||||
return &{{ $client }}{config: cfg}
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{/* Add the "DebugLog()" only to the "User" type. */}}
|
||||
{{ with $n := byName $ "User" }}
|
||||
{{ $client := print $n.Name "Client" }}
|
||||
func (c *{{ $client }}) DebugLog(fn func(...any)) *{{ $client }} {
|
||||
if c.debug {
|
||||
return c
|
||||
}
|
||||
cfg := config{driver: dialect.Debug(c.driver, c.log), log: fn, debug: true, hooks: c.hooks}
|
||||
return &{{ $client }}{config: cfg}
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ end }}
|
||||
25
examples/entcpkg/ent/template/entinit.tmpl
Normal file
25
examples/entcpkg/ent/template/entinit.tmpl
Normal file
@@ -0,0 +1,25 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/mixin"
|
||||
)
|
||||
|
||||
// {{ . }} holds the schema definition for the {{ . }} entity.
|
||||
type {{ . }} struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Mixins of the {{ . }}.
|
||||
func ({{ . }}) Mixins() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mixin.Time{},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the {{ . }}.
|
||||
func ({{ . }}) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
// Fields go here.
|
||||
}
|
||||
}
|
||||
12
examples/entcpkg/ent/template/static.tmpl
Normal file
12
examples/entcpkg/ent/template/static.tmpl
Normal file
@@ -0,0 +1,12 @@
|
||||
{{/* The line below tells Intellij/GoLand to enable the autocompletion based *gen.Type type. */}}
|
||||
{{/* gotype: entgo.io/ent/entc/gen.Type */}}
|
||||
|
||||
{{/* A template for adding additional static fields to specific types. */}}
|
||||
{{ define "model/fields/additional" }}
|
||||
{{- /* Add static fields to the "Card" entity. */}}
|
||||
{{- if eq $.Name "User" }}
|
||||
{{- /* A usage of an external function. */ -}}
|
||||
// StaticField defined by templates (titled {{ title "staticField" }}).
|
||||
StaticField string `json:"static_field,omitempty"{{ with $.Config.Annotations.RQL }} {{ .StructTag }}:"static_field"{{ end }}`
|
||||
{{- end }}
|
||||
{{ end }}
|
||||
16
examples/entcpkg/ent/template/stringer.tmpl
Normal file
16
examples/entcpkg/ent/template/stringer.tmpl
Normal file
@@ -0,0 +1,16 @@
|
||||
{{/* The line below tells Intellij/GoLand to enable the autocompletion based *gen.Type type. */}}
|
||||
{{/* gotype: entgo.io/ent/entc/gen.Type */}}
|
||||
|
||||
{{ define "model/additional/stringer" }}
|
||||
|
||||
{{/* A template that adds the "GoString" method to all generated models on the same file they are defined. */}}
|
||||
|
||||
// GoString implements the fmt.GoStringer interface.
|
||||
func ({{ $.Receiver }} *{{ $.Name }}) GoString() string {
|
||||
b, err := json.MarshalIndent({{ $.Receiver }}, "", "\t")
|
||||
if err != nil {
|
||||
return err.Error()
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
{{ end }}
|
||||
Reference in New Issue
Block a user