Исправление описаний моделей БД
continuous-integration/drone/tag Build is passing
Details
continuous-integration/drone/tag Build is passing
Details
This commit is contained in:
parent
2536a92ecb
commit
37524245b8
|
@ -25,7 +25,7 @@ func TestDBModelAttrib(t *testing.T) {
|
|||
Name: "Field_naME1",
|
||||
Type: "int",
|
||||
Description: "Hello world",
|
||||
})
|
||||
}, false)
|
||||
if str != "`gorm:\"column:field_name1;type:INT;comment:Hello world\"`" {
|
||||
t.Fail()
|
||||
}
|
||||
|
|
|
@ -196,14 +196,21 @@ func FieldTypeDB(field *structs.Field) string {
|
|||
}
|
||||
|
||||
// Генерирование описания таблиц в БД
|
||||
func FieldDescript(field *structs.Field) (str string) {
|
||||
str = fmt.Sprintf("`gorm:\"column:%s;type:%s", FieldDBName(field), FieldTypeDB(field))
|
||||
field.Description = strings.Trim(field.Description, " ")
|
||||
if field.Description != "" {
|
||||
str += fmt.Sprintf(";comment:%s", field.Description)
|
||||
func FieldDescript(field *structs.Field, fieldId bool) (str string) {
|
||||
str = "`"
|
||||
if fieldId {
|
||||
str = fmt.Sprintf("`gorm:\"column:%s;type:%s", FieldDBName(field), FieldTypeDB(field))
|
||||
field.Description = strings.Trim(field.Description, " ")
|
||||
if field.Description != "" {
|
||||
str += fmt.Sprintf(";comment:%s", field.Description)
|
||||
}
|
||||
str += "\""
|
||||
}
|
||||
if fieldId {
|
||||
str = fmt.Sprintf("%s json:\"%sId,omitempty\"`", str, FieldJsonName(field))
|
||||
} else {
|
||||
str = fmt.Sprintf("%s json:\"%s,omitempty\"`", str, FieldJsonName(field))
|
||||
}
|
||||
str += "\""
|
||||
str = fmt.Sprintf("%s json:\"%s,omitempty\"`", str, FieldJsonName(field))
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -17,16 +17,16 @@ type {{ fieldNamePrepare .Name }} struct {
|
|||
{{ end }}
|
||||
|
||||
{{ range $index, $field := .Fields }}
|
||||
{{ fieldName $field }} {{ fieldType $field }} {{ fieldDescript $field }}
|
||||
{{ fieldName $field }} {{ fieldType $field }} `gorm:"column:{{ fieldNameLowerPrepare $field.Name }}" json:"{{ fieldNameLowerPrepare $field.Name }},omitenpty"`
|
||||
{{ end }}
|
||||
|
||||
{{ range $index, $field := .Children }}
|
||||
{{ fieldNamePrepare $field }} []{{ fieldNamePrepare $field }}
|
||||
{{ fieldNamePrepare $field }} []{{ fieldNamePrepare $field }} `json:"{{ fieldNamePrepare $field }},omitenpty"`
|
||||
{{ end }}
|
||||
|
||||
{{ range $index, $field := .FkFields }}
|
||||
{{ fieldName $field }}ID {{ fieldType $field }} {{ fieldDescript $field }}
|
||||
{{ fieldName $field }} *{{ if eq $field.Name "Parent" }}{{ fieldNamePrepare $.Name }}{{ else }}{{ fieldName $field }}{{ end }} {{ fieldDescript $field }}
|
||||
{{ fieldName $field }}ID {{ fieldType $field }} `gorm:"column:{{ fieldNameLowerPrepare $field.Name }}" json:"{{ fieldNameLowerPrepare $field.Name }}Id,omitenpty"`
|
||||
{{ fieldName $field }} *{{ if eq $field.Name "Parent" }}{{ fieldNamePrepare $.Name }}{{ else }}{{ fieldName $field }}{{ end }} `json:"{{ fieldNameLowerPrepare $field.Name }},omitenpty"`
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue