mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-01 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: string;
|
||||
length: number;
|
||||
packet: FieldPacket;
|
||||
string: () => string;
|
||||
buffer: () => number[];
|
||||
};
|
||||
@@ -13,11 +16,21 @@ export const typeCast = (field: Field, next: () => void) => {
|
||||
case 'TIMESTAMP2':
|
||||
case 'NEWDATE':
|
||||
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':
|
||||
return field.length === 1 ? field.string() === '1' : next();
|
||||
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:
|
||||
return next();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user