mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
38 lines
1.2 KiB
Cheetah
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 }}
|