Skip to content

Commit

Permalink
fix: add warning for not specifying charset when using JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
jyoonPro-bagel committed Oct 28, 2022
1 parent f33437f commit 722d967
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/parsers/text_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ function compile(fields, options, config) {
table: field.table,
name: field.name,
string: function(encoding = field.encoding) {
if (field.columnType === Types.JSON && encoding === field.encoding) {

This comment has been minimized.

Copy link
@sidorares

sidorares Oct 28, 2022

Owner

would it be better to check for "non-utf8" here? Alternatively assign later, e.g function(encoding) { /* check for "typeof encoding === 'undefined'" to see if set, and use later as encoding ?? field.encoding ... */ }

// JSON columns are always returned as BINARY, so we have to
// handle them according to JSON specs and use "utf8",
// see https://github.com/sidorares/node-mysql2/issues/1661
console.warn(`typeCast: JSON column "${field.name}" is interpreted as BINARY by default, recommended to manually set utf8 encoding: \`field.string("utf8")\``);
}

return _this.packet.readLengthCodedString(encoding);
},
buffer: function() {
Expand Down

0 comments on commit 722d967

Please sign in to comment.