从数据库获取表结构直接生成代码
This commit is contained in:
@@ -9,8 +9,14 @@ import (
|
||||
type {{.StructName}} struct {
|
||||
gorm.Model {{- range .Fields}}
|
||||
{{- if eq .FieldType "bool" }}
|
||||
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'"`
|
||||
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'{{- if .DataType -}};type:'{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}'{{- end -}}"`
|
||||
{{- else }}
|
||||
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'"`
|
||||
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:'{{.Comment}}'{{- if .DataType -}};type:'{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}'{{- end -}}"`
|
||||
{{- end }} {{- end }}
|
||||
}
|
||||
|
||||
{{ if .TableName }}
|
||||
func ({{.StructName}}) TableName() string {
|
||||
return "{{.TableName}}"
|
||||
}
|
||||
{{ end }}
|
Reference in New Issue
Block a user