doc/faq: add table collation/charset example using annotation (#2183)

* update faq.md, add new question

question: How to change the character set and/or collation of a MySQL table?

* Update doc/md/faq.md

Co-authored-by: MasseElch <12862103+masseelch@users.noreply.github.com>

* Update doc/md/faq.md

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>
Co-authored-by: MasseElch <12862103+masseelch@users.noreply.github.com>
This commit is contained in:
idc77
2021-11-30 20:58:54 +01:00
committed by GitHub
parent c88cddaf81
commit 5c91f752b7

View File

@@ -21,7 +21,8 @@ sidebar_label: FAQ
[How to store Protobuf objects in a BLOB column?](#how-to-store-protobuf-objects-in-a-blob-column)
[How to add `CHECK` constraints to table?](#how-to-add-check-constraints-to-table)
[How to define a custom precision numeric field?](#how-to-define-a-custom-precision-numeric-field)
[How to configure two or more `DB` to separate read and write?](#how-to-configure-two-or-more-db-to-separate-read-and-write)
[How to configure two or more `DB` to separate read and write?](#how-to-configure-two-or-more-db-to-separate-read-and-write)
[How to change the character set and/or collation of a MySQL table?](#how-to-change-the-character-set-and-or-collation-of-a-mysql-table)
## Answers
@@ -759,3 +760,22 @@ func (d *multiDriver) Close() error {
}
```
#### How to change the character set and/or collation of a MySQL table?
By default for MySQL the character set `utf8mb4` is used and the collation of `utf8mb4_bin`.
However if you'd like to change the schema's character set and/or collation you need to use an annotation.
Here's an example where we set the character set to `ascii` and the collation to `ascii_general_ci`.
```go
// Annotations of the Entity.
func (Entity) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{
Charset: "ascii",
Collation: "ascii_general_ci",
},
}
}
```