Skip to content

Commit 7087743

Browse files
committed
Fix handling of null timestamps and numbers
1 parent 2b538cd commit 7087743

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

index.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,22 @@ function hydrateRecord (record, fields) {
2929

3030
value = getAuroraDataValue(value);
3131

32-
switch (field.typeName) {
33-
case 'DECIMAL':
34-
value = Number(value);
35-
break;
36-
37-
case 'DATE':
38-
case 'DATETIME':
39-
case 'TIMESTAMP':
40-
case 'YEAR':
41-
value = new Date(value + 'Z');
42-
break;
32+
if (value !== null) {
33+
switch (field.typeName) {
34+
case 'DECIMAL':
35+
value = Number(value);
36+
break;
4337

44-
default:
45-
break;
38+
case 'DATE':
39+
case 'DATETIME':
40+
case 'TIMESTAMP':
41+
case 'YEAR':
42+
value = new Date(value + 'Z');
43+
break;
44+
45+
default:
46+
break;
47+
}
4648
}
4749

4850
row[field.label] = value;

tests/constants.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,22 @@ module.exports = {
197197
type: 92,
198198
typeName: 'TIME'
199199
},
200+
{
201+
arrayBaseColumnType: 0,
202+
isAutoIncrement: false,
203+
isCaseSensitive: false,
204+
isCurrency: false,
205+
isSigned: false,
206+
label: 'timestamp_null',
207+
name: 'timestamp_null',
208+
nullable: 1,
209+
precision: 19,
210+
scale: 0,
211+
schemaName: '',
212+
tableName: 'foo',
213+
type: 93,
214+
typeName: 'TIMESTAMP'
215+
},
200216
{
201217
arrayBaseColumnType: 0,
202218
isAutoIncrement: false,
@@ -365,6 +381,9 @@ module.exports = {
365381
{
366382
stringValue: '04:31:56.734'
367383
},
384+
{
385+
isNull: true
386+
},
368387
{
369388
stringValue: 'foo'
370389
},
@@ -421,6 +440,7 @@ module.exports = {
421440
datetime3: new Date('2020-04-16T15:36:54.384Z'),
422441
timestamp3: new Date('2020-04-16T03:21:45.938Z'),
423442
time3: '04:31:56.734',
443+
timestamp_null: null,
424444
varchar: 'foo',
425445
varbinary: Buffer.from([98, 97, 114]),
426446
blob: Buffer.from([98, 108, 111, 103]),

0 commit comments

Comments
 (0)