mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-03 22:20:56 +00:00
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:
1 parent
08766b7075
commit
71f5c69cd8
1 file changed
+16
-1
+16
-1
@@ -6,7 +6,22 @@ const BINARY_CHARSET = 63;
|
|||||||
* node-mysql2 v3.9.0 introduced (breaking) typecasting for execute methods.
|
* node-mysql2 v3.9.0 introduced (breaking) typecasting for execute methods.
|
||||||
*/
|
*/
|
||||||
export function typeCastExecute(field: TypeCastField, next: TypeCastNext) {
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user