Skip to content

Commit d03f87e

Browse files
committed
Update tests.
1 parent f5fc07a commit d03f87e

File tree

7 files changed

+83
-172
lines changed

7 files changed

+83
-172
lines changed

packages/api/src/api.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SqliteArguments, SqliteRowObject } from '@sqlite-js/driver';
1+
import { SqliteArguments, SqliteObjectRow } from '@sqlite-js/driver';
22

33
export type SqliteDatabase = SqliteConnectionPool & SqliteConnection;
44

@@ -61,7 +61,7 @@ export interface ReservedSqliteConnection extends SqliteConnection {
6161
}
6262

6363
export interface QueryInterface {
64-
prepare<T extends SqliteRowObject>(
64+
prepare<T extends SqliteObjectRow>(
6565
query: string,
6666
args?: SqliteArguments,
6767
options?: QueryOptions
@@ -73,7 +73,7 @@ export interface QueryInterface {
7373
options?: ReserveConnectionOptions
7474
): Promise<RunResult>;
7575

76-
stream<T extends SqliteRowObject>(
76+
stream<T extends SqliteObjectRow>(
7777
query: string,
7878
args: SqliteArguments,
7979
options?: StreamOptions & ReserveConnectionOptions
@@ -84,7 +84,7 @@ export interface QueryInterface {
8484
*
8585
* When called on a connection pool, uses readonly: true by default.
8686
*/
87-
select<T extends SqliteRowObject>(
87+
select<T extends SqliteObjectRow>(
8888
query: string,
8989
args?: SqliteArguments,
9090
options?: QueryOptions & ReserveConnectionOptions
@@ -99,7 +99,7 @@ export interface QueryInterface {
9999
* @param args
100100
* @param options
101101
*/
102-
get<T extends SqliteRowObject>(
102+
get<T extends SqliteObjectRow>(
103103
query: string,
104104
args?: SqliteArguments,
105105
options?: QueryOptions & ReserveConnectionOptions
@@ -114,7 +114,7 @@ export interface QueryInterface {
114114
* @param args
115115
* @param options
116116
*/
117-
getOptional<T extends SqliteRowObject>(
117+
getOptional<T extends SqliteObjectRow>(
118118
query: string,
119119
args?: SqliteArguments,
120120
options?: QueryOptions & ReserveConnectionOptions
@@ -236,7 +236,7 @@ export interface RunResult {
236236
lastInsertRowId: bigint;
237237
}
238238

239-
export interface PreparedQuery<T extends SqliteRowObject> {
239+
export interface PreparedQuery<T extends SqliteObjectRow> {
240240
parse(): Promise<{ columns: string[] }>;
241241

242242
/**

packages/api/src/impl.ts

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
SqliteDriverConnection,
2727
SqliteDriverConnectionPool,
2828
SqliteDriverStatement,
29-
SqliteRowObject
29+
SqliteObjectRow
3030
} from '@sqlite-js/driver';
3131

3232
export class ConnectionPoolImpl
@@ -54,7 +54,7 @@ export class ConnectionPoolImpl
5454
throw new Error('Method not implemented.');
5555
}
5656

57-
prepare<T extends SqliteRowObject>(
57+
prepare<T extends SqliteObjectRow>(
5858
sql: string,
5959
args?: SqliteArguments
6060
): PreparedQuery<T> {
@@ -103,7 +103,7 @@ export class ConnectionPoolImpl
103103
return tx;
104104
}
105105

106-
async *stream<T extends SqliteRowObject>(
106+
async *stream<T extends SqliteObjectRow>(
107107
query: string,
108108
args?: SqliteArguments,
109109
options?: (StreamOptions & ReserveConnectionOptions) | undefined
@@ -116,7 +116,7 @@ export class ConnectionPoolImpl
116116
}
117117
}
118118

119-
async select<T extends SqliteRowObject>(
119+
async select<T extends SqliteObjectRow>(
120120
query: string,
121121
args?: SqliteArguments | undefined,
122122
options?: (QueryOptions & ReserveConnectionOptions) | undefined
@@ -129,7 +129,7 @@ export class ConnectionPoolImpl
129129
}
130130
}
131131

132-
async get<T extends SqliteRowObject>(
132+
async get<T extends SqliteObjectRow>(
133133
query: string,
134134
args?: SqliteArguments | undefined,
135135
options?: (QueryOptions & ReserveConnectionOptions) | undefined
@@ -142,7 +142,7 @@ export class ConnectionPoolImpl
142142
}
143143
}
144144

145-
async getOptional<T extends SqliteRowObject>(
145+
async getOptional<T extends SqliteObjectRow>(
146146
query: string,
147147
args?: SqliteArguments | undefined,
148148
options?: (QueryOptions & ReserveConnectionOptions) | undefined
@@ -202,7 +202,7 @@ export class ReservedConnectionImpl implements ReservedSqliteConnection {
202202
}
203203
}
204204

205-
prepare<T extends SqliteRowObject>(
205+
prepare<T extends SqliteObjectRow>(
206206
sql: string,
207207
args?: SqliteArguments,
208208
options?: QueryOptions
@@ -252,31 +252,31 @@ export class ReservedConnectionImpl implements ReservedSqliteConnection {
252252
return this.connection.run(query, args);
253253
}
254254

255-
stream<T extends SqliteRowObject>(
255+
stream<T extends SqliteObjectRow>(
256256
query: string,
257257
args: SqliteArguments | undefined,
258258
options?: StreamOptions | undefined
259259
): AsyncGenerator<T[], any, unknown> {
260260
return this.connection.stream(query, args, options);
261261
}
262262

263-
select<T extends SqliteRowObject>(
263+
select<T extends SqliteObjectRow>(
264264
query: string,
265265
args?: SqliteArguments | undefined,
266266
options?: QueryOptions | undefined
267267
): Promise<T[]> {
268268
return this.connection.select(query, args, options);
269269
}
270270

271-
get<T extends SqliteRowObject>(
271+
get<T extends SqliteObjectRow>(
272272
query: string,
273273
args?: SqliteArguments,
274274
options?: QueryOptions
275275
): Promise<T> {
276276
return this.connection.get(query, args, options);
277277
}
278278

279-
getOptional<T extends SqliteRowObject>(
279+
getOptional<T extends SqliteObjectRow>(
280280
query: string,
281281
args?: SqliteArguments,
282282
options?: QueryOptions
@@ -295,11 +295,13 @@ export class ConnectionImpl implements SqliteConnection {
295295

296296
private init() {
297297
this._beginExclusive ??= this.prepare('BEGIN EXCLUSIVE', undefined, {
298-
persist: true
298+
autoFinalize: true
299+
});
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, {
303+
autoFinalize: true
299304
});
300-
this._begin ??= this.prepare('BEGIN', undefined, { persist: true });
301-
this.commit ??= this.prepare('COMMIT', undefined, { persist: true });
302-
this.rollback ??= this.prepare('ROLLBACK', undefined, { persist: true });
303305
}
304306

305307
async begin(options?: TransactionOptions): Promise<SqliteBeginTransaction> {
@@ -362,7 +364,7 @@ export class ConnectionImpl implements SqliteConnection {
362364
this.rollback?.dispose();
363365
}
364366

365-
prepare<T extends SqliteRowObject>(
367+
prepare<T extends SqliteObjectRow>(
366368
sql: string,
367369
args?: SqliteArguments,
368370
options?: PrepareOptions
@@ -392,7 +394,7 @@ export class ConnectionImpl implements SqliteConnection {
392394
return await statement.run();
393395
}
394396

395-
async *stream<T extends SqliteRowObject>(
397+
async *stream<T extends SqliteObjectRow>(
396398
query: string | PreparedQuery<T>,
397399
args: SqliteArguments | undefined,
398400
options?: StreamOptions | undefined
@@ -416,7 +418,7 @@ export class ConnectionImpl implements SqliteConnection {
416418
}
417419
}
418420

419-
async select<T extends SqliteRowObject>(
421+
async select<T extends SqliteObjectRow>(
420422
query: string,
421423
args?: SqliteArguments,
422424
options?: (QueryOptions & ReserveConnectionOptions) | undefined
@@ -432,7 +434,7 @@ export class ConnectionImpl implements SqliteConnection {
432434
return rows as T[];
433435
}
434436

435-
async get<T extends SqliteRowObject>(
437+
async get<T extends SqliteObjectRow>(
436438
query: string,
437439
args?: SqliteArguments,
438440
options?: (QueryOptions & ReserveConnectionOptions) | undefined
@@ -444,7 +446,7 @@ export class ConnectionImpl implements SqliteConnection {
444446
return row;
445447
}
446448

447-
async getOptional<T extends SqliteRowObject>(
449+
async getOptional<T extends SqliteObjectRow>(
448450
query: string,
449451
args?: SqliteArguments,
450452
options?: (QueryOptions & ReserveConnectionOptions) | undefined
@@ -467,7 +469,7 @@ export class TransactionImpl implements SqliteTransaction {
467469
await this.con.rollback!.select();
468470
}
469471

470-
prepare<T extends SqliteRowObject>(
472+
prepare<T extends SqliteObjectRow>(
471473
sql: string,
472474
args?: SqliteArguments,
473475
options?: QueryOptions
@@ -486,31 +488,31 @@ export class TransactionImpl implements SqliteTransaction {
486488
return this.con.run(query, args);
487489
}
488490

489-
stream<T extends SqliteRowObject>(
491+
stream<T extends SqliteObjectRow>(
490492
query: string,
491493
args: SqliteArguments,
492494
options?: StreamOptions | undefined
493495
): AsyncGenerator<T[], any, unknown> {
494496
return this.con.stream(query, args, options);
495497
}
496498

497-
select<T extends SqliteRowObject>(
499+
select<T extends SqliteObjectRow>(
498500
query: string,
499501
args?: SqliteArguments,
500502
options?: QueryOptions | undefined
501503
): Promise<T[]> {
502504
return this.con.select(query, args, options);
503505
}
504506

505-
get<T extends SqliteRowObject>(
507+
get<T extends SqliteObjectRow>(
506508
query: string,
507509
args?: SqliteArguments,
508510
options?: QueryOptions | undefined
509511
): Promise<T> {
510512
return this.con.get(query, args, options);
511513
}
512514

513-
getOptional<T extends SqliteRowObject>(
515+
getOptional<T extends SqliteObjectRow>(
514516
query: string,
515517
args?: SqliteArguments,
516518
options?: QueryOptions | undefined
@@ -556,7 +558,7 @@ class BeginTransactionImpl
556558
}
557559
}
558560

559-
async select<T extends SqliteRowObject>(
561+
async select<T extends SqliteObjectRow>(
560562
query: string,
561563
args?: SqliteArguments,
562564
options?: (QueryOptions & ReserveConnectionOptions) | undefined
@@ -590,7 +592,7 @@ class BeginTransactionImpl
590592
}
591593
}
592594

593-
class ConnectionPoolPreparedQueryImpl<T extends SqliteRowObject>
595+
class ConnectionPoolPreparedQueryImpl<T extends SqliteObjectRow>
594596
implements PreparedQuery<T>
595597
{
596598
[Symbol.dispose]: () => void = undefined as any;
@@ -668,7 +670,7 @@ class ConnectionPoolPreparedQueryImpl<T extends SqliteRowObject>
668670
}
669671
}
670672

671-
class ConnectionPreparedQueryImpl<T extends SqliteRowObject>
673+
class ConnectionPreparedQueryImpl<T extends SqliteObjectRow>
672674
implements PreparedQuery<T>
673675
{
674676
[Symbol.dispose]: () => void = undefined as any;

packages/better-sqlite3-driver/src/sync-driver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class BetterSqlitePreparedStatement implements InternalStatement {
3636
constructor(statement: bsqlite.Statement, options: PrepareOptions) {
3737
this.statement = statement;
3838
this.options = options;
39-
this.persisted = options.persist ?? false;
39+
this.persisted = options.autoFinalize ?? false;
4040

4141
if (typeof Symbol.dispose != 'undefined') {
4242
this[Symbol.dispose] = () => this.finalize();

0 commit comments

Comments
 (0)