loopback4, node mysql connector character set support utf8mb4

Scene: A database sql statement contains emoji emoticons, such as micro letter containing login nicknames emoticons, the database can not be inserted using utf8 will prompt 'Incorrect string value: \' \\ xF0 \\ x9F \\ x90 \\ xBE \\ xE5 \\ xAE ... \ 'for column \' nick_name \ 'at row 1',

Cause: loopback4 do the back-end database character set has been set to utf8mb4, but due to the mysql connector versions loopback4 use may be too low, there is the character set issue,

"mysql": "2.17.1",

"loopback-connector-mysql": "^5.4.2",

Solution, to directly modify node_modules / mysql / lib / ConnectionConfig.js line 55

this.charsetNumber = (options.charset)
? ConnectionConfig.getCharsetNumber(options.charset)
: options.charsetNumber || Charsets. UTF8_GENERAL_CI
;
Changed
this.charsetNumber = (options.charset)
? ConnectionConfig.getCharsetNumber(options.charset)
: options.charsetNumber || Charsets. UTF8MB4_UNICODE_CI;

Modification is completed, the resumption of direct nodejs to take effect.

Reference documents: https://github.com/mysqljs/mysql/pull/1408/commits/b6b7f06b88e9c899244fa6219933dbe6cbab2c89

Guess you like

Origin www.cnblogs.com/vincegod/p/11355554.html