[Bug241] Remove control characters from mysql column comment
This commit is contained in:
parent
dbcf614140
commit
bb22b80984
3 changed files with 104 additions and 3 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package metadata
|
||||
|
||||
import "regexp"
|
||||
|
||||
// Column struct
|
||||
type Column struct {
|
||||
Name string
|
||||
|
|
@ -10,6 +12,16 @@ type Column struct {
|
|||
Comment string
|
||||
}
|
||||
|
||||
// GoLangComment returns column comment without ascii control characters
|
||||
func (c Column) GoLangComment() string {
|
||||
if c.Comment == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
// remove ascii control characters from string
|
||||
return regexp.MustCompile(`[[:cntrl:]]+`).ReplaceAllString(c.Comment, "")
|
||||
}
|
||||
|
||||
// DataTypeKind is database type kind(base, enum, user-defined, array)
|
||||
type DataTypeKind string
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ type {{structImplName}} struct {
|
|||
// Columns
|
||||
{{- range $i, $c := .Columns}}
|
||||
{{- $field := columnField $c}}
|
||||
{{$field.Name}} {{dialect.PackageName}}.Column{{$field.Type}} {{- if $c.Comment }} // {{$c.Comment}} {{end}}
|
||||
{{$field.Name}} {{dialect.PackageName}}.Column{{$field.Type}} {{- if $c.Comment }} // {{$c.GoLangComment}} {{end}}
|
||||
{{- end}}
|
||||
|
||||
AllColumns {{dialect.PackageName}}.ColumnList
|
||||
|
|
@ -122,7 +122,7 @@ import (
|
|||
type {{$modelTableTemplate.TypeName}} struct {
|
||||
{{- range .Columns}}
|
||||
{{- $field := structField .}}
|
||||
{{$field.Name}} {{$field.Type.Name}} ` + "{{$field.TagsString}}" + ` {{- if .Comment }} // {{.Comment}} {{end}}
|
||||
{{$field.Name}} {{$field.Type.Name}} ` + "{{$field.TagsString}}" + ` {{- if .Comment }} // {{.GoLangComment}} {{end}}
|
||||
{{- end}}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue