model.go.template 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package models
  2. import (
  3. {{- $bb := false -}}
  4. {{- range .Columns -}}
  5. {{$z := .IsQuery}}
  6. {{- if ($z) }}
  7. {{if eq .GoType "time.Time"}}{{- $bb = true -}}{{- end -}}
  8. {{- end -}}
  9. {{- end -}}
  10. {{- range .Columns -}}
  11. {{if eq .GoType "time.Time"}}{{- $bb = true -}}{{- end -}}
  12. {{- end -}}
  13. {{- if eq $bb true -}}
  14. "time"
  15. {{- end }}
  16. "go-admin/common/models"
  17. )
  18. type {{.ClassName}} struct {
  19. models.Model
  20. {{ range .Columns -}}
  21. {{$x := .Pk}}
  22. {{- if ($x) }}
  23. {{- else if eq .GoField "CreatedAt" -}}
  24. {{- else if eq .GoField "UpdatedAt" -}}
  25. {{- else if eq .GoField "DeletedAt" -}}
  26. {{- else if eq .GoField "CreateBy" -}}
  27. {{- else if eq .GoField "UpdateBy" -}}
  28. {{- else }}
  29. {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};comment:{{- if eq .ColumnComment "" -}}{{.GoField}}{{- else -}}{{.ColumnComment}}{{end -}}"` {{end -}}
  30. {{- end }}
  31. models.ModelTime
  32. models.ControlBy
  33. }
  34. func ({{.ClassName}}) TableName() string {
  35. return "{{.TBName}}"
  36. }
  37. func (e *{{.ClassName}}) Generate() models.ActiveRecord {
  38. o := *e
  39. return &o
  40. }
  41. func (e *{{.ClassName}}) GetId() interface{} {
  42. return e.{{.PkGoField}}
  43. }