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 }}
|
||||
Reference in New Issue
Block a user