model.go.template 886 Bytes
Newer Older
haoyanbin's avatar
1  
haoyanbin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
package models

import (
   // "gorm.io/gorm"

	"go-admin/common/models"
)

type {{.ClassName}} struct {
    models.Model
    {{ range .Columns -}}
    {{$x := .Pk}}
    {{- if ($x) }}
    {{- else if eq .GoField "CreatedAt" -}}
    {{- else if eq .GoField "UpdatedAt" -}}
    {{- else if eq .GoField "DeletedAt" -}}
    {{- else if eq .GoField "CreateBy" -}}
    {{- else if eq .GoField "UpdateBy" -}}
    {{- else }}
    {{.GoField}} {{.GoType}} `json:"{{.JsonField}}" gorm:"type:{{.ColumnType}};comment:{{- if eq .ColumnComment "" -}}{{.GoField}}{{- else -}}{{.ColumnComment}}{{end -}}"` {{end -}}
    {{- end }}
    models.ModelTime
    models.ControlBy
}

func ({{.ClassName}}) TableName() string {
    return "{{.TBName}}"
}

func (e *{{.ClassName}}) Generate() models.ActiveRecord {
	o := *e
	return &o
}

func (e *{{.ClassName}}) GetId() interface{} {
	return e.{{.PkGoField}}
}