mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-03 14:38:50 +00:00
refactor(utils/typeCast): Change BIT and BLOB types
BIT fields should only cast as boolean if they have a length of 1.
This commit is contained in:
1 parent
4975a17a31
commit
7096237ce2
1 file changed
+15
-2
+15
-2
@@ -1,6 +1,9 @@
|
|||||||
|
import { FieldPacket } from 'mysql2';
|
||||||
|
|
||||||
type Field = {
|
type Field = {
|
||||||
type: string;
|
type: string;
|
||||||
length: number;
|
length: number;
|
||||||
|
packet: FieldPacket;
|
||||||
string: () => string;
|
string: () => string;
|
||||||
buffer: () => number[];
|
buffer: () => number[];
|
||||||
};
|
};
|
||||||
@@ -13,11 +16,21 @@ export const typeCast = (field: Field, next: () => void) => {
|
|||||||
case 'TIMESTAMP2':
|
case 'TIMESTAMP2':
|
||||||
case 'NEWDATE':
|
case 'NEWDATE':
|
||||||
case 'DATE':
|
case 'DATE':
|
||||||
return field.type === 'DATE' ? new Date(field.string() + ' 00:00:00').getTime() : new Date(field.string()).getTime();
|
return field.type === 'DATE'
|
||||||
|
? new Date(field.string() + ' 00:00:00').getTime()
|
||||||
|
: new Date(field.string()).getTime();
|
||||||
case 'TINY':
|
case 'TINY':
|
||||||
return field.length === 1 ? field.string() === '1' : next();
|
return field.length === 1 ? field.string() === '1' : next();
|
||||||
case 'BIT':
|
case 'BIT':
|
||||||
return field.buffer()[0] === 1;
|
return field.length === 1 ? field.buffer()[0] === 1 : field.buffer()[0];
|
||||||
|
case 'TINY_BLOB':
|
||||||
|
case 'MEDIUM_BLOB':
|
||||||
|
case 'LONG_BLOB':
|
||||||
|
case 'BLOB':
|
||||||
|
if (field.packet.charsetNr === 63) {
|
||||||
|
return [...field.buffer()];
|
||||||
|
}
|
||||||
|
return field.string();
|
||||||
default:
|
default:
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user