fix: Add charset to cast binary and json data correctly

This commit is contained in:
Jaime Filho committed 2022-02-18 19:12:46 -03:00
1 parent 0c7620613f
commit 8611cc0762
2 files changed
+16 -1

No files matched your search

+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();