feat(utils/typeCast): support date typecasting for binary protocol

Support for execute typecasting (used by prepare/rawExecute methods)
was added recently, but did not support dates until 3.10.2.
This commit is contained in:
Linden committed 2024-07-04 11:21:57 +10:00
1 parent 08766b7075
commit 71f5c69cd8
1 file changed
+16 -1
+16 -1
View File
@@ -6,7 +6,22 @@ const BINARY_CHARSET = 63;
* node-mysql2 v3.9.0 introduced (breaking) typecasting for execute methods.
*/
export function typeCastExecute(field: TypeCastField, next: TypeCastNext) {
return next();
switch (field.type) {
case 'DATETIME':
case 'DATETIME2':
case 'TIMESTAMP':
case 'TIMESTAMP2':
case 'NEWDATE': {
const value = field.string();
return value ? new Date(value).getTime() : null;
}
case 'DATE': {
const value = field.string();
return value ? new Date(value + ' 00:00:00').getTime() : null;
}
default:
return next();
}
}
/**