model.go.template 871 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package models
  2. import (
  3. "gorm.io/gorm"
  4. "device-manage/common/models"
  5. )
  6. type {{.ClassName}} struct {
  7. gorm.Model
  8. models.ControlBy
  9. {{ range .Columns -}}
  10. {{$x := .Pk}}
  11. {{- if ($x) }}
  12. {{- else if eq .GoField "CreatedAt" -}}
  13. {{- else if eq .GoField "UpdatedAt" -}}
  14. {{- else if eq .GoField "DeletedAt" -}}
  15. {{- else if eq .GoField "CreateBy" -}}
  16. {{- else if eq .GoField "UpdateBy" -}}
  17. {{- else }}
  18. {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};comment:{{- if eq .ColumnComment "" -}}{{.GoField}}{{- else -}}{{.ColumnComment}}{{end -}}"` // {{end -}}
  19. {{- end }}
  20. }
  21. func ({{.ClassName}}) TableName() string {
  22. return "{{.TBName}}"
  23. }
  24. func (e *{{.ClassName}}) Generate() models.ActiveRecord {
  25. o := *e
  26. return &o
  27. }
  28. func (e *{{.ClassName}}) GetId() interface{} {
  29. return e.{{.PkGoField}}
  30. }