Files
ent/examples/entcpkg/ent/template/debug.tmpl
2021-04-09 17:53:04 +03:00

38 lines
1.2 KiB
Cheetah

{{ 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(...interface{})) *{{ $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 }}