github.com/yoogoc/kratos-scaffold@v0.0.0-20240402032722-a538b3c18955/generator/tmpl/data_ent_schema.tmpl (about) 1 {{- /*gotype: github.com/yoogoc/kratos-scaffold/generator.Data*/ -}} 2 package schema 3 4 import ( 5 "time" 6 7 "entgo.io/ent" 8 "entgo.io/ent/schema/field" 9 ) 10 11 // {{ .Name }} holds the schema definition for the {{ .Name }} entity. 12 type {{ .Name }} struct { 13 ent.Schema 14 } 15 16 // Fields of the {{ .Name }}. 17 func ({{ .Name }}) Fields() []ent.Field { 18 return []ent.Field{ 19 {{- range $i, $f := .EntFields }} 20 field.{{ $f.FieldType.StringEnt }}("{{$f.Name | ToSnake}}"), 21 {{- end }} 22 {{- if .NeedAuditField }} 23 field.Time("created_at").Immutable().Default(time.Now), 24 field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now), 25 {{- end }} 26 } 27 } 28 29 // Edges of the {{ .Name }}. 30 func ({{ .Name }}) Edges() []ent.Edge { 31 return nil 32 }