File tree 2 files changed +8
-3
lines changed 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -626,6 +626,11 @@ describe('cast', () => {
626
626
expect ( cast ( { name : 'test' , type : 'FLOAT64' } , '2.32' ) ) . toEqual ( 2.32 )
627
627
} )
628
628
629
+ test ( 'casts binary data to array of 8-bit unsigned integers' , ( ) => {
630
+ expect ( cast ( { name : 'test' , type : 'BLOB' } , '' ) ) . toEqual ( new Uint8Array ( [ ] ) )
631
+ expect ( cast ( { name : 'test' , type : 'BLOB' } , 'Å' ) ) . toEqual ( new Uint8Array ( [ 197 ] ) )
632
+ } )
633
+
629
634
test ( 'casts JSON string to JSON object' , ( ) => {
630
635
expect ( cast ( { name : 'test' , type : 'JSON' } , '{ "foo": "bar" }' ) ) . toStrictEqual ( { foo : 'bar' } )
631
636
} )
Original file line number Diff line number Diff line change @@ -379,7 +379,7 @@ function decodeRow(row: QueryResultRow): Array<string | null> {
379
379
}
380
380
381
381
export function cast ( field : Field , value : string | null ) : any {
382
- if ( value === '' || value == null ) {
382
+ if ( value == null ) {
383
383
return value
384
384
}
385
385
@@ -393,7 +393,7 @@ export function cast(field: Field, value: string | null): any {
393
393
case 'UINT24' :
394
394
case 'UINT32' :
395
395
case 'YEAR' :
396
- return parseInt ( value , 10 )
396
+ return value ? parseInt ( value , 10 ) : value
397
397
case 'FLOAT32' :
398
398
case 'FLOAT64' :
399
399
return parseFloat ( value )
@@ -412,7 +412,7 @@ export function cast(field: Field, value: string | null): any {
412
412
case 'BINARY' :
413
413
return uint8Array ( value )
414
414
case 'JSON' :
415
- return JSON . parse ( decode ( value ) )
415
+ return value ? JSON . parse ( decode ( value ) ) : value
416
416
default :
417
417
return decode ( value )
418
418
}
You can’t perform that action at this time.
0 commit comments