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

View File

@@ -176,6 +176,7 @@ type Column struct {
Nullable bool // null or not null attribute.
Default interface{} // default value.
Enums []string // enum values.
Collation string // collation type (utf8mb4_unicode_ci, utf8mb4_general_ci)
typ string // row column type (used for Rows.Scan).
indexes Indexes // linked indexes.
foreign *ForeignKey // linked foreign-key.
@@ -307,6 +308,13 @@ func (c Column) supportDefault() bool {
}
}
// collation adds `COLLATE collation_name`.
func (c *Column) collation(b *sql.ColumnBuilder) {
if c.Collation != "" {
b.Attr("COLLATE " + c.Collation)
}
}
// unique adds the `UNIQUE` attribute if the column is a unique type.
// it is exist in a different function to share the common declaration
// between the two dialects.