@@ -77,7 +77,12 @@ const JSON_SUBTYPE = 74;
77
77
78
78
const BIG_MAX = BigInt ( Number . MAX_SAFE_INTEGER ) ;
79
79
80
- function getColumn ( handle : Deno . PointerValue , i : number , int64 : boolean ) : any {
80
+ function getColumn (
81
+ handle : Deno . PointerValue ,
82
+ i : number ,
83
+ int64 : boolean ,
84
+ parseJson : boolean ,
85
+ ) : any {
81
86
const ty = sqlite3_column_type ( handle , i ) ;
82
87
83
88
if ( ty === SQLITE_INTEGER && ! int64 ) return sqlite3_column_int ( handle , i ) ;
@@ -89,7 +94,7 @@ function getColumn(handle: Deno.PointerValue, i: number, int64: boolean): any {
89
94
const text = readCstr ( ptr , 0 ) ;
90
95
const value = sqlite3_column_value ( handle , i ) ;
91
96
const subtype = sqlite3_value_subtype ( value ) ;
92
- if ( subtype === JSON_SUBTYPE ) {
97
+ if ( subtype === JSON_SUBTYPE && parseJson ) {
93
98
try {
94
99
return JSON . parse ( text ) ;
95
100
} catch ( _error ) {
@@ -142,16 +147,6 @@ export class Statement<TStatement extends object = Record<string, any>> {
142
147
#hasNoArgs = false ;
143
148
#unsafeConcurrency;
144
149
145
- /**
146
- * Whether the query might call into JavaScript or not.
147
- *
148
- * Must enable if the query makes use of user defined functions,
149
- * otherwise there can be V8 crashes.
150
- *
151
- * Off by default. Causes performance degradation.
152
- */
153
- callback = false ;
154
-
155
150
/** Unsafe Raw (pointer) to the sqlite object */
156
151
get unsafeHandle ( ) : Deno . PointerValue {
157
152
return this . #handle;
@@ -233,12 +228,6 @@ export class Statement<TStatement extends object = Record<string, any>> {
233
228
}
234
229
}
235
230
236
- /** Shorthand for `this.callback = true`. Enables calling user defined functions. */
237
- enableCallback ( ) : this {
238
- this . callback = true ;
239
- return this ;
240
- }
241
-
242
231
/** Get bind parameter name by index */
243
232
bindParameterName ( i : number ) : string {
244
233
return readCstr ( sqlite3_bind_parameter_name ( this . #handle, i ) ! ) ;
@@ -437,7 +426,7 @@ export class Statement<TStatement extends object = Record<string, any>> {
437
426
return function(h) {
438
427
return [${
439
428
Array . from ( { length : columnCount } ) . map ( ( _ , i ) =>
440
- `getColumn(h, ${ i } , ${ this . db . int64 } )`
429
+ `getColumn(h, ${ i } , ${ this . db . int64 } , ${ this . db . parseJson } )`
441
430
)
442
431
. join ( ", " )
443
432
} ];
@@ -470,7 +459,7 @@ export class Statement<TStatement extends object = Record<string, any>> {
470
459
return function(h) {
471
460
return [${
472
461
Array . from ( { length : columnCount } ) . map ( ( _ , i ) =>
473
- `getColumn(h, ${ i } , ${ this . db . int64 } )`
462
+ `getColumn(h, ${ i } , ${ this . db . int64 } , ${ this . db . parseJson } )`
474
463
)
475
464
. join ( ", " )
476
465
} ];
@@ -504,7 +493,7 @@ export class Statement<TStatement extends object = Record<string, any>> {
504
493
return {
505
494
${
506
495
columnNames . map ( ( name , i ) =>
507
- `"${ name } ": getColumn(h, ${ i } , ${ this . db . int64 } )`
496
+ `"${ name } ": getColumn(h, ${ i } , ${ this . db . int64 } , ${ this . db . parseJson } )`
508
497
) . join ( ",\n" )
509
498
}
510
499
};
@@ -562,6 +551,7 @@ export class Statement<TStatement extends object = Record<string, any>> {
562
551
) : T | undefined {
563
552
const handle = this . #handle;
564
553
const int64 = this . db . int64 ;
554
+ const parseJson = this . db . parseJson ;
565
555
const arr = new Array ( sqlite3_column_count ( handle ) ) ;
566
556
sqlite3_reset ( handle ) ;
567
557
if ( ! this . #hasNoArgs && ! this . #bound) {
@@ -580,7 +570,7 @@ export class Statement<TStatement extends object = Record<string, any>> {
580
570
581
571
if ( status === SQLITE3_ROW ) {
582
572
for ( let i = 0 ; i < arr . length ; i ++ ) {
583
- arr [ i ] = getColumn ( handle , i , int64 ) ;
573
+ arr [ i ] = getColumn ( handle , i , int64 , parseJson ) ;
584
574
}
585
575
sqlite3_reset ( this . #handle) ;
586
576
return arr as T ;
@@ -594,13 +584,14 @@ export class Statement<TStatement extends object = Record<string, any>> {
594
584
#valueNoArgs< T extends Array < unknown > > ( ) : T | undefined {
595
585
const handle = this . #handle;
596
586
const int64 = this . db . int64 ;
587
+ const parseJson = this . db . parseJson ;
597
588
const cc = sqlite3_column_count ( handle ) ;
598
589
const arr = new Array ( cc ) ;
599
590
sqlite3_reset ( handle ) ;
600
591
const status = sqlite3_step ( handle ) ;
601
592
if ( status === SQLITE3_ROW ) {
602
593
for ( let i = 0 ; i < cc ; i ++ ) {
603
- arr [ i ] = getColumn ( handle , i , int64 ) ;
594
+ arr [ i ] = getColumn ( handle , i , int64 , parseJson ) ;
604
595
}
605
596
sqlite3_reset ( this . #handle) ;
606
597
return arr as T ;
@@ -636,7 +627,7 @@ export class Statement<TStatement extends object = Record<string, any>> {
636
627
) : T | undefined {
637
628
const handle = this . #handle;
638
629
const int64 = this . db . int64 ;
639
-
630
+ const parseJson = this . db . parseJson ;
640
631
const columnNames = this . columnNames ( ) ;
641
632
642
633
const row : Record < string , unknown > = { } ;
@@ -657,7 +648,7 @@ export class Statement<TStatement extends object = Record<string, any>> {
657
648
658
649
if ( status === SQLITE3_ROW ) {
659
650
for ( let i = 0 ; i < columnNames . length ; i ++ ) {
660
- row [ columnNames [ i ] ] = getColumn ( handle , i , int64 ) ;
651
+ row [ columnNames [ i ] ] = getColumn ( handle , i , int64 , parseJson ) ;
661
652
}
662
653
sqlite3_reset ( this . #handle) ;
663
654
return row as T ;
@@ -671,13 +662,14 @@ export class Statement<TStatement extends object = Record<string, any>> {
671
662
#getNoArgs< T extends object > ( ) : T | undefined {
672
663
const handle = this . #handle;
673
664
const int64 = this . db . int64 ;
665
+ const parseJson = this . db . parseJson ;
674
666
const columnNames = this . columnNames ( ) ;
675
667
const row : Record < string , unknown > = this . #rowObject;
676
668
sqlite3_reset ( handle ) ;
677
669
const status = sqlite3_step ( handle ) ;
678
670
if ( status === SQLITE3_ROW ) {
679
671
for ( let i = 0 ; i < columnNames ?. length ; i ++ ) {
680
- row [ columnNames [ i ] ] = getColumn ( handle , i , int64 ) ;
672
+ row [ columnNames [ i ] ] = getColumn ( handle , i , int64 , parseJson ) ;
681
673
}
682
674
sqlite3_reset ( handle ) ;
683
675
return row as T ;
0 commit comments