dialect/sql/schema: add field collation support (#1548)

* specific field collation support

* go generate ./...
This commit is contained in:
Mahmudul Haque
2021-05-09 21:09:08 +06:00
committed by GitHub
parent a2a6af4cd8
commit ba954ebeec
6 changed files with 52 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@@ -39,6 +39,7 @@ var (
{{- with $c.Attr }} Attr: "{{ . }}",{{ end }}
{{- with $c.Enums }} Enums: []string{ {{ range $e := . }}"{{ $e }}",{{ end }} },{{ end }}
{{- if not (isNil $c.Default) }} Default: {{ $c.Default }},{{ end }}
{{- if ne (len $c.Collation) 0 }} Collation: {{ $c.Collation }},{{ end }}
{{- with $c.SchemaType }} SchemaType: map[string]string{ {{ range $k, $v := . }}"{{ $k }}": "{{ $v }}",{{ end }}}{{ end }}},
{{- end }}
}

View File

@@ -1155,6 +1155,11 @@ func (f Field) Column() *schema.Column {
if ant := f.EntSQL(); ant != nil && ant.Default != "" {
c.Default = strconv.Quote(ant.Default)
}
// Override the collation defined in the
// schema if it was provided by an annotation.
if ant := f.EntSQL(); ant != nil && ant.Collation != "" {
c.Collation = strconv.Quote(ant.Collation)
}
if f.def != nil {
c.SchemaType = f.def.SchemaType
}