@@ -196,6 +196,39 @@ export class Statement<TStatement extends object = Record<string, any>> {
196
196
return this . #bindParameterCount;
197
197
}
198
198
199
+ int64 ?: boolean ;
200
+ parseJson ?: boolean ;
201
+
202
+ enableInt64 ( ) : this {
203
+ this . int64 = true ;
204
+ return this ;
205
+ }
206
+
207
+ enableParseJson ( ) : this {
208
+ this . parseJson = true ;
209
+ return this ;
210
+ }
211
+
212
+ disableInt64 ( ) : this {
213
+ this . int64 = false ;
214
+ return this ;
215
+ }
216
+
217
+ disableParseJson ( ) : this {
218
+ this . parseJson = false ;
219
+ return this ;
220
+ }
221
+
222
+ defaultInt64 ( ) : this {
223
+ this . int64 = undefined ;
224
+ return this ;
225
+ }
226
+
227
+ defaultParseJson ( ) : this {
228
+ this . parseJson = undefined ;
229
+ return this ;
230
+ }
231
+
199
232
constructor ( public db : Database , sql : string ) {
200
233
const pHandle = new BigUint64Array ( 1 ) ;
201
234
unwrap (
@@ -423,10 +456,10 @@ export class Statement<TStatement extends object = Record<string, any>> {
423
456
const getRowArray = new Function (
424
457
"getColumn" ,
425
458
`
426
- return function(h) {
459
+ return function(h, int64, parseJson ) {
427
460
return [${
428
461
Array . from ( { length : columnCount } ) . map ( ( _ , i ) =>
429
- `getColumn(h, ${ i } , ${ this . db . int64 } , ${ this . db . parseJson } )`
462
+ `getColumn(h, ${ i } , int64, parseJson)`
430
463
)
431
464
. join ( ", " )
432
465
} ];
@@ -435,7 +468,7 @@ export class Statement<TStatement extends object = Record<string, any>> {
435
468
) ( getColumn ) ;
436
469
let status = sqlite3_step ( handle ) ;
437
470
while ( status === SQLITE3_ROW ) {
438
- result . push ( getRowArray ( handle ) ) ;
471
+ result . push ( getRowArray ( handle , this . int64 ?? this . db . int64 , this . parseJson ?? this . db . parseJson ) ) ;
439
472
status = sqlite3_step ( handle ) ;
440
473
}
441
474
if ( status !== SQLITE3_DONE ) {
@@ -456,10 +489,10 @@ export class Statement<TStatement extends object = Record<string, any>> {
456
489
const getRowArray = new Function (
457
490
"getColumn" ,
458
491
`
459
- return function(h) {
492
+ return function(h, int64, parseJson ) {
460
493
return [${
461
494
Array . from ( { length : columnCount } ) . map ( ( _ , i ) =>
462
- `getColumn(h, ${ i } , ${ this . db . int64 } , ${ this . db . parseJson } )`
495
+ `getColumn(h, ${ i } , int64, parseJson)`
463
496
)
464
497
. join ( ", " )
465
498
} ];
@@ -468,7 +501,7 @@ export class Statement<TStatement extends object = Record<string, any>> {
468
501
) ( getColumn ) ;
469
502
let status = sqlite3_step ( handle ) ;
470
503
while ( status === SQLITE3_ROW ) {
471
- result . push ( getRowArray ( handle ) ) ;
504
+ result . push ( getRowArray ( handle , this . int64 ?? this . db . int64 , this . parseJson ?? this . db . parseJson ) ) ;
472
505
status = sqlite3_step ( handle ) ;
473
506
}
474
507
if ( ! this . #hasNoArgs && ! this . #bound && params . length ) {
@@ -481,19 +514,19 @@ export class Statement<TStatement extends object = Record<string, any>> {
481
514
return result as T [ ] ;
482
515
}
483
516
484
- #rowObjectFn: ( ( h : Deno . PointerValue ) => any ) | undefined ;
517
+ #rowObjectFn: ( ( h : Deno . PointerValue , int64 : boolean , parseJson : boolean ) => any ) | undefined ;
485
518
486
- getRowObject ( ) : ( h : Deno . PointerValue ) => any {
519
+ getRowObject ( ) : ( h : Deno . PointerValue , int64 : boolean , parseJson : boolean ) => any {
487
520
if ( ! this . #rowObjectFn || ! this . #unsafeConcurrency) {
488
521
const columnNames = this . columnNames ( ) ;
489
522
const getRowObject = new Function (
490
523
"getColumn" ,
491
524
`
492
- return function(h) {
525
+ return function(h, int64, parseJson ) {
493
526
return {
494
527
${
495
528
columnNames . map ( ( name , i ) =>
496
- `"${ name } ": getColumn(h, ${ i } , ${ this . db . int64 } , ${ this . db . parseJson } )`
529
+ `"${ name } ": getColumn(h, ${ i } , int64, parseJson)`
497
530
) . join ( ",\n" )
498
531
}
499
532
};
@@ -507,12 +540,14 @@ export class Statement<TStatement extends object = Record<string, any>> {
507
540
508
541
#allNoArgs< T extends object > ( ) : T [ ] {
509
542
const handle = this . #handle;
543
+ const int64 = this . int64 ?? this . db . int64 ;
544
+ const parseJson = this . parseJson ?? this . db . parseJson ;
510
545
this . #begin( ) ;
511
546
const getRowObject = this . getRowObject ( ) ;
512
547
const result : T [ ] = [ ] ;
513
548
let status = sqlite3_step ( handle ) ;
514
549
while ( status === SQLITE3_ROW ) {
515
- result . push ( getRowObject ( handle ) ) ;
550
+ result . push ( getRowObject ( handle , int64 , parseJson ) ) ;
516
551
status = sqlite3_step ( handle ) ;
517
552
}
518
553
if ( status !== SQLITE3_DONE ) {
@@ -526,13 +561,15 @@ export class Statement<TStatement extends object = Record<string, any>> {
526
561
...params : RestBindParameters
527
562
) : T [ ] {
528
563
const handle = this . #handle;
564
+ const int64 = this . int64 ?? this . db . int64 ;
565
+ const parseJson = this . parseJson ?? this . db . parseJson ;
529
566
this . #begin( ) ;
530
567
this . #bindAll( params ) ;
531
568
const getRowObject = this . getRowObject ( ) ;
532
569
const result : T [ ] = [ ] ;
533
570
let status = sqlite3_step ( handle ) ;
534
571
while ( status === SQLITE3_ROW ) {
535
- result . push ( getRowObject ( handle ) ) ;
572
+ result . push ( getRowObject ( handle , int64 , parseJson ) ) ;
536
573
status = sqlite3_step ( handle ) ;
537
574
}
538
575
if ( ! this . #hasNoArgs && ! this . #bound && params . length ) {
@@ -550,8 +587,8 @@ export class Statement<TStatement extends object = Record<string, any>> {
550
587
...params : RestBindParameters
551
588
) : T | undefined {
552
589
const handle = this . #handle;
553
- const int64 = this . db . int64 ;
554
- const parseJson = this . db . parseJson ;
590
+ const int64 = this . int64 ?? this . db . int64 ;
591
+ const parseJson = this . parseJson ?? this . db . parseJson ;
555
592
const arr = new Array ( sqlite3_column_count ( handle ) ) ;
556
593
sqlite3_reset ( handle ) ;
557
594
if ( ! this . #hasNoArgs && ! this . #bound) {
@@ -583,8 +620,8 @@ export class Statement<TStatement extends object = Record<string, any>> {
583
620
584
621
#valueNoArgs< T extends Array < unknown > > ( ) : T | undefined {
585
622
const handle = this . #handle;
586
- const int64 = this . db . int64 ;
587
- const parseJson = this . db . parseJson ;
623
+ const int64 = this . int64 ?? this . db . int64 ;
624
+ const parseJson = this . parseJson ?? this . db . parseJson ;
588
625
const cc = sqlite3_column_count ( handle ) ;
589
626
const arr = new Array ( cc ) ;
590
627
sqlite3_reset ( handle ) ;
@@ -626,8 +663,8 @@ export class Statement<TStatement extends object = Record<string, any>> {
626
663
...params : RestBindParameters
627
664
) : T | undefined {
628
665
const handle = this . #handle;
629
- const int64 = this . db . int64 ;
630
- const parseJson = this . db . parseJson ;
666
+ const int64 = this . int64 ?? this . db . int64 ;
667
+ const parseJson = this . parseJson ?? this . db . parseJson ;
631
668
const columnNames = this . columnNames ( ) ;
632
669
633
670
const row : Record < string , unknown > = { } ;
@@ -661,8 +698,8 @@ export class Statement<TStatement extends object = Record<string, any>> {
661
698
662
699
#getNoArgs< T extends object > ( ) : T | undefined {
663
700
const handle = this . #handle;
664
- const int64 = this . db . int64 ;
665
- const parseJson = this . db . parseJson ;
701
+ const int64 = this . int64 ?? this . db . int64 ;
702
+ const parseJson = this . parseJson ?? this . db . parseJson ;
666
703
const columnNames = this . columnNames ( ) ;
667
704
const row : Record < string , unknown > = this . #rowObject;
668
705
sqlite3_reset ( handle ) ;
@@ -696,12 +733,14 @@ export class Statement<TStatement extends object = Record<string, any>> {
696
733
697
734
/** Iterate over resultant rows from query. */
698
735
* iter ( ...params : RestBindParameters ) : IterableIterator < any > {
699
- this . #begin( ) ;
736
+ this . #begin( ) ;
700
737
this . #bindAll( params ) ;
701
738
const getRowObject = this . getRowObject ( ) ;
739
+ const int64 = this . int64 ?? this . db . int64 ;
740
+ const parseJson = this . parseJson ?? this . db . parseJson ;
702
741
let status = sqlite3_step ( this . #handle) ;
703
742
while ( status === SQLITE3_ROW ) {
704
- yield getRowObject ( this . #handle) ;
743
+ yield getRowObject ( this . #handle, int64 , parseJson ) ;
705
744
status = sqlite3_step ( this . #handle) ;
706
745
}
707
746
if ( status !== SQLITE3_DONE ) {
0 commit comments