Merge pull request #86 from jaimeadf/fix/charset

fix: Add charset to cast binary and json data correctly
This commit is contained in:
Linden authored and GitHub committed 2022-02-19 09:14:58 +11:00
commit 82f0382518
2 files changed
+16 -1

No files matched your search

+12
View File
@@ -191,6 +191,18 @@ index c612f66..02dbe22 100644
case 'number':
type = Types.DOUBLE;
diff --git a/node_modules/mysql2/lib/parsers/text_parser.js b/node_modules/mysql2/lib/parsers/text_parser.js
index 0af4a7a..bce66bc 100644
--- a/node_modules/mysql2/lib/parsers/text_parser.js
+++ b/node_modules/mysql2/lib/parsers/text_parser.js
@@ -85,6 +85,7 @@ function compile(fields, options, config) {
db: field.schema,
table: field.table,
name: field.name,
+ charset: field.characterSet,
string: function() {
return _this.packet.readLengthCodedString(field.encoding);
},
diff --git a/node_modules/mysql2/promise.d.ts b/node_modules/mysql2/promise.d.ts
index 6ab3d6f..64246e8 100644
--- a/node_modules/mysql2/promise.d.ts
+4 -1
View File
@@ -1,9 +1,12 @@
import { FieldPacket } from 'mysql2';
const BINARY_CHARSET = 63;
type Field = {
type: string;
length: number;
packet: FieldPacket;
charset: number;
string: () => string;
buffer: () => number[];
};
@@ -27,7 +30,7 @@ export const typeCast = (field: Field, next: () => void) => {
case 'MEDIUM_BLOB':
case 'LONG_BLOB':
case 'BLOB':
if (field.packet?.charsetNr === 63) {
if (field.charset === BINARY_CHARSET) {
return [...field.buffer()];
}
return field.string();