@@ -54,11 +54,8 @@ export class ConnectionPoolImpl
54
54
throw new Error ( 'Method not implemented.' ) ;
55
55
}
56
56
57
- prepare < T extends SqliteObjectRow > (
58
- sql : string ,
59
- args ?: SqliteArguments
60
- ) : PreparedQuery < T > {
61
- return new ConnectionPoolPreparedQueryImpl < T > ( this , sql , args ) ;
57
+ prepare < T extends SqliteObjectRow > ( sql : string ) : PreparedQuery < T > {
58
+ return new ConnectionPoolPreparedQueryImpl < T > ( this , sql ) ;
62
59
}
63
60
64
61
pipeline ( options ?: ReserveConnectionOptions | undefined ) : QueryPipeline {
@@ -202,12 +199,8 @@ export class ReservedConnectionImpl implements ReservedSqliteConnection {
202
199
}
203
200
}
204
201
205
- prepare < T extends SqliteObjectRow > (
206
- sql : string ,
207
- args ?: SqliteArguments ,
208
- options ?: QueryOptions
209
- ) : PreparedQuery < T > {
210
- return this . connection . prepare ( sql , args , options ) ;
202
+ prepare < T extends SqliteObjectRow > ( sql : string ) : PreparedQuery < T > {
203
+ return this . connection . prepare ( sql ) ;
211
204
}
212
205
213
206
pipeline ( ) : QueryPipeline {
@@ -294,12 +287,12 @@ export class ConnectionImpl implements SqliteConnection {
294
287
constructor ( private driver : SqliteDriverConnection ) { }
295
288
296
289
private init ( ) {
297
- this . _beginExclusive ??= this . prepare ( 'BEGIN EXCLUSIVE' , undefined , {
290
+ this . _beginExclusive ??= this . prepare ( 'BEGIN EXCLUSIVE' , {
298
291
autoFinalize : true
299
292
} ) ;
300
- this . _begin ??= this . prepare ( 'BEGIN' , undefined , { autoFinalize : true } ) ;
301
- this . commit ??= this . prepare ( 'COMMIT' , undefined , { autoFinalize : true } ) ;
302
- this . rollback ??= this . prepare ( 'ROLLBACK' , undefined , {
293
+ this . _begin ??= this . prepare ( 'BEGIN' , { autoFinalize : true } ) ;
294
+ this . commit ??= this . prepare ( 'COMMIT' , { autoFinalize : true } ) ;
295
+ this . rollback ??= this . prepare ( 'ROLLBACK' , {
303
296
autoFinalize : true
304
297
} ) ;
305
298
}
@@ -366,20 +359,10 @@ export class ConnectionImpl implements SqliteConnection {
366
359
367
360
prepare < T extends SqliteObjectRow > (
368
361
sql : string ,
369
- args ?: SqliteArguments ,
370
362
options ?: PrepareOptions
371
363
) : PreparedQuery < T > {
372
364
const statement = this . driver . prepare ( sql , options ) ;
373
- if ( args ) {
374
- statement . bind ( args ) ;
375
- }
376
- return new ConnectionPreparedQueryImpl (
377
- this ,
378
- this . driver ,
379
- statement ,
380
- sql ,
381
- args
382
- ) ;
365
+ return new ConnectionPreparedQueryImpl ( this , this . driver , statement , sql ) ;
383
366
}
384
367
385
368
pipeline ( ) : QueryPipeline {
@@ -388,49 +371,31 @@ export class ConnectionImpl implements SqliteConnection {
388
371
389
372
async run ( query : string , args : SqliteArguments ) : Promise < RunResult > {
390
373
using statement = this . driver . prepare ( query ) ;
391
- if ( args != null ) {
392
- statement . bind ( args ) ;
393
- }
394
- return await statement . run ( ) ;
374
+ return await statement . run ( args ) ;
395
375
}
396
376
397
377
async * stream < T extends SqliteObjectRow > (
398
- query : string | PreparedQuery < T > ,
378
+ query : string ,
399
379
args : SqliteArguments | undefined ,
400
380
options ?: StreamOptions | undefined
401
381
) : AsyncGenerator < T [ ] , void , unknown > {
402
- using statement = this . driver . prepare ( query as string , {
382
+ using statement = this . driver . prepare ( query ) ;
383
+ const chunkSize = options ?. chunkSize ;
384
+
385
+ const iter = statement . stream ( args , {
386
+ chunkMaxRows : chunkSize ,
403
387
bigint : options ?. bigint
404
388
} ) ;
405
- if ( args != null ) {
406
- statement . bind ( args ) ;
407
- }
408
- const chunkSize = options ?. chunkSize ?? 100 ;
409
-
410
- while ( true ) {
411
- const { rows, done } = await statement . step ( chunkSize ) ;
412
- if ( rows != null ) {
413
- yield rows as T [ ] ;
414
- }
415
- if ( done ) {
416
- break ;
417
- }
418
- }
389
+ yield * iter as AsyncGenerator < T [ ] , void , unknown > ;
419
390
}
420
391
421
392
async select < T extends SqliteObjectRow > (
422
393
query : string ,
423
394
args ?: SqliteArguments ,
424
395
options ?: ( QueryOptions & ReserveConnectionOptions ) | undefined
425
396
) : Promise < T [ ] > {
426
- using statement = this . driver . prepare ( query , {
427
- bigint : options ?. bigint ,
428
- rawResults : false
429
- } ) ;
430
- if ( args != null ) {
431
- statement . bind ( args ) ;
432
- }
433
- const { rows } = await statement . step ( ) ;
397
+ using statement = this . driver . prepare ( query ) ;
398
+ const rows = await statement . all ( args , { bigint : options ?. bigint } ) ;
434
399
return rows as T [ ] ;
435
400
}
436
401
@@ -469,12 +434,8 @@ export class TransactionImpl implements SqliteTransaction {
469
434
await this . con . rollback ! . select ( ) ;
470
435
}
471
436
472
- prepare < T extends SqliteObjectRow > (
473
- sql : string ,
474
- args ?: SqliteArguments ,
475
- options ?: QueryOptions
476
- ) : PreparedQuery < T > {
477
- const q = this . con . prepare < T > ( sql , args , options ) ;
437
+ prepare < T extends SqliteObjectRow > ( sql : string ) : PreparedQuery < T > {
438
+ const q = this . con . prepare < T > ( sql ) ;
478
439
// FIXME: auto-dispose these after transaction commit / rollback
479
440
this . preparedQueries . push ( q ) ;
480
441
return q ;
@@ -601,8 +562,7 @@ class ConnectionPoolPreparedQueryImpl<T extends SqliteObjectRow>
601
562
602
563
constructor (
603
564
private context : ConnectionPoolImpl ,
604
- public sql : string ,
605
- public args : SqliteArguments
565
+ public sql : string
606
566
) {
607
567
if ( typeof Symbol . dispose != 'undefined' ) {
608
568
this [ Symbol . dispose ] = ( ) => this . dispose ( ) ;
@@ -663,7 +623,7 @@ class ConnectionPoolPreparedQueryImpl<T extends SqliteObjectRow>
663
623
const cimpl = connection as ConnectionImpl ;
664
624
let sub = this . byConnection . get ( cimpl ) ;
665
625
if ( sub == null ) {
666
- sub = cimpl . prepare ( this . sql , this . args ) ;
626
+ sub = cimpl . prepare ( this . sql ) ;
667
627
this . byConnection . set ( cimpl , sub ) ;
668
628
}
669
629
return sub ;
@@ -681,8 +641,7 @@ class ConnectionPreparedQueryImpl<T extends SqliteObjectRow>
681
641
private context : ConnectionImpl ,
682
642
private driver : SqliteDriverConnection ,
683
643
public statement : SqliteDriverStatement ,
684
- public sql : string ,
685
- public args : SqliteArguments
644
+ public sql : string
686
645
) {
687
646
if ( typeof Symbol . dispose != 'undefined' ) {
688
647
this [ Symbol . dispose ] = ( ) => this . dispose ( ) ;
@@ -700,42 +659,22 @@ class ConnectionPreparedQueryImpl<T extends SqliteObjectRow>
700
659
args ?: SqliteArguments ,
701
660
options ?: StreamOptions | undefined
702
661
) : AsyncGenerator < T [ ] , any , unknown > {
703
- const chunkSize = options ?. chunkSize ?? 10 ;
704
- if ( args != null ) {
705
- this . statement . bind ( args ) ;
706
- }
707
- try {
708
- while ( true ) {
709
- const { rows, done } = await this . statement . step ( chunkSize ) ;
710
- if ( rows != null ) {
711
- yield rows as T [ ] ;
712
- }
713
- if ( done ) {
714
- break ;
715
- }
716
- }
717
- } finally {
718
- this . statement . reset ( ) ;
662
+ const chunkSize = options ?. chunkSize ;
663
+ const iter = this . statement . stream ( args , {
664
+ chunkMaxRows : chunkSize
665
+ } ) ;
666
+ for await ( let chunk of iter ) {
667
+ yield chunk as T [ ] ;
719
668
}
720
669
}
721
670
722
671
async run ( args ?: SqliteArguments ) : Promise < RunResult > {
723
- if ( args != null ) {
724
- this . statement . bind ( args ) ;
725
- }
726
- return await this . statement . run ( ) ;
672
+ return await this . statement . run ( args ) ;
727
673
}
728
674
729
675
async select ( args ?: SqliteArguments ) : Promise < T [ ] > {
730
- try {
731
- if ( args != null ) {
732
- this . statement . bind ( args ) ;
733
- }
734
- const { rows } = await this . statement . step ( ) ;
735
- return rows as T [ ] ;
736
- } finally {
737
- this . statement . reset ( ) ;
738
- }
676
+ const rows = await this . statement . all ( args ) ;
677
+ return rows as T [ ] ;
739
678
}
740
679
741
680
dispose ( ) : void {
@@ -753,19 +692,14 @@ class QueryPipelineImpl implements QueryPipeline {
753
692
this . count += 1 ;
754
693
if ( typeof query == 'string' ) {
755
694
using statement = this . driver . prepare ( query ) ;
756
- if ( args ) {
757
- statement . bind ( args ) ;
758
- }
759
- this . lastPromise = statement . step ( undefined , {
695
+ this . lastPromise = statement . run ( args , {
760
696
requireTransaction : true
761
697
} ) ;
762
698
} else if ( query instanceof ConnectionPreparedQueryImpl ) {
763
699
const statement = query . statement ;
764
- statement . bind ( args ?? [ ] ) ;
765
- this . lastPromise = statement . step ( undefined , {
700
+ this . lastPromise = statement . run ( args , {
766
701
requireTransaction : true
767
702
} ) ;
768
- statement . reset ( ) ;
769
703
} else {
770
704
throw new Error ( 'not implemented yet' ) ;
771
705
}
0 commit comments