@@ -2,7 +2,10 @@ import type {
2
2
ArrayRow ,
3
3
Row ,
4
4
SqlClient ,
5
+ SqlClientPool ,
5
6
SqlConnectionOptions ,
7
+ SqlPoolClient ,
8
+ SqlPoolClientOptions ,
6
9
SqlPreparable ,
7
10
SqlPreparedStatement ,
8
11
SqlQueriable ,
@@ -16,6 +19,7 @@ import type { DatabaseOpenOptions } from './database.js';
16
19
import {
17
20
SqliteCloseEvent ,
18
21
SqliteConnectEvent ,
22
+ SqliteEvents ,
19
23
SqliteEventTarget
20
24
} from './events.js' ;
21
25
import {
@@ -26,6 +30,7 @@ import {
26
30
import { SqliteTransactionError } from './errors.js' ;
27
31
import { mergeQueryOptions , transformToAsyncGenerator } from './util.js' ;
28
32
import {
33
+ ReservedConnection ,
29
34
SqliteDriverConnection ,
30
35
SqliteDriverConnectionPool ,
31
36
SqliteDriverStatement ,
@@ -437,34 +442,43 @@ export class SqliteTransactionable
437
442
}
438
443
}
439
444
440
- /**
441
- * Sqlite client
442
- */
443
- export class SqliteClient
445
+ class SqlitePoolClient
444
446
extends SqliteTransactionable
445
447
implements
446
- SqlClient <
447
- SqliteEventTarget ,
448
+ SqlPoolClient <
448
449
SqliteConnectionOptions ,
450
+ SqliteConnection ,
449
451
SqliteParameterType ,
450
452
SqliteQueryOptions ,
451
- SqliteConnection ,
452
453
SqlitePreparedStatement ,
453
454
SqliteTransactionOptions ,
454
455
SqliteTransaction
455
456
>
456
457
{
457
458
readonly eventTarget : SqliteEventTarget ;
459
+ readonly reserved : ReservedConnection ;
460
+ readonly connectionUrl : string ;
458
461
459
462
constructor (
460
463
connectionUrl : string ,
461
- driver : SqliteDriverConnectionPool ,
464
+ reserved : ReservedConnection ,
462
465
options : SqliteClientOptions = { }
463
466
) {
464
- const conn = new SqliteConnection ( connectionUrl , driver , options ) ;
467
+ const conn = new SqliteConnection (
468
+ connectionUrl ,
469
+ reserved . connection ,
470
+ options
471
+ ) ;
465
472
super ( conn , options ) ;
473
+ this . reserved = reserved ;
474
+ this . connectionUrl = connectionUrl ;
466
475
this . eventTarget = new SqliteEventTarget ( ) ;
467
476
}
477
+ disposed : boolean = false ;
478
+ async release ( ) : Promise < void > {
479
+ this . disposed = true ;
480
+ await this . reserved . release ( ) ;
481
+ }
468
482
469
483
async connect ( ) : Promise < void > {
470
484
await this . connection . connect ( ) ;
@@ -484,3 +498,66 @@ export class SqliteClient
484
498
await this . close ( ) ;
485
499
}
486
500
}
501
+
502
+ /**
503
+ * Sqlite client
504
+ */
505
+ export class SqliteClientPool
506
+ implements
507
+ SqlClientPool <
508
+ SqliteConnectionOptions ,
509
+ SqliteParameterType ,
510
+ SqliteQueryOptions ,
511
+ SqliteConnection ,
512
+ SqlitePreparedStatement ,
513
+ SqliteTransactionOptions ,
514
+ SqliteTransaction
515
+ >
516
+ {
517
+ readonly eventTarget : SqliteEventTarget ;
518
+
519
+ readonly connectionUrl : string ;
520
+ readonly pool : SqliteDriverConnectionPool ;
521
+ readonly options : SqliteClientOptions ;
522
+ readonly connected = true ;
523
+
524
+ constructor (
525
+ connectionUrl : string ,
526
+ pool : SqliteDriverConnectionPool ,
527
+ options : SqliteClientOptions = { }
528
+ ) {
529
+ this . pool = pool ;
530
+ this . connectionUrl = connectionUrl ;
531
+ this . options = options ;
532
+ this . eventTarget = new SqliteEventTarget ( ) ;
533
+ }
534
+
535
+ async acquire ( ) : Promise <
536
+ SqlPoolClient <
537
+ SqliteConnectionOptions ,
538
+ SqliteConnection ,
539
+ SqliteValue ,
540
+ SqliteQueryOptions ,
541
+ SqlitePreparedStatement ,
542
+ SqliteTransactionOptions ,
543
+ SqliteTransaction ,
544
+ SqlPoolClientOptions
545
+ >
546
+ > {
547
+ const reserved = await this . pool . reserveConnection ( ) ;
548
+ return new SqlitePoolClient ( this . connectionUrl , reserved , this . options ) ;
549
+ }
550
+
551
+ async connect ( ) : Promise < void > {
552
+ // No-op
553
+ }
554
+
555
+ async close ( ) : Promise < void > {
556
+ // TODO: this.eventTarget.dispatchEvent(new SqliteCloseEvent({}));
557
+ await this . pool . close ( ) ;
558
+ }
559
+
560
+ async [ Symbol . asyncDispose ] ( ) : Promise < void > {
561
+ await this . close ( ) ;
562
+ }
563
+ }
0 commit comments