snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
Atlas CI Public / lint (push) Failing after 13s
Atlas CI Public / sync (push) Has been skipped

This commit is contained in:
upstream-mirror
2026-09-15 22:12:36 +05:00
commit 4b3ad0b611
2680 changed files with 719472 additions and 0 deletions

View 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 }}

View 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.
}
}

View 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 }}

View 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 }}