File tree Expand file tree Collapse file tree 3 files changed +18
-7
lines changed
packages/better-sqlite3-driver/src Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -12,13 +12,13 @@ import {
12
12
import { WorkerDriverConnection } from '@sqlite-js/driver/worker_threads' ;
13
13
import type * as bsqlite from 'better-sqlite3' ;
14
14
15
- export interface BetterSqliteDriverOptions
16
- extends ConnectionPoolOptions ,
17
- bsqlite . Options {
15
+ export interface BetterSqliteDriverOptions extends ConnectionPoolOptions {
18
16
/**
19
17
* Specify a custom path to a worker script, to customize the loading process.
20
18
*/
21
19
workerPath ?: string | URL ;
20
+
21
+ loadExtensions ?: string [ ] ;
22
22
}
23
23
24
24
export class BetterSqliteDriver implements SqliteDriverConnectionPool {
@@ -52,7 +52,7 @@ export class BetterSqliteDriver implements SqliteDriverConnectionPool {
52
52
async openConnection ( connectionOptions ) {
53
53
return new WorkerDriverConnection ( workerPath , path , {
54
54
...options ,
55
- readonly : ( options ?. readonly ?? connectionOptions ?. readonly ) || false
55
+ readonly : connectionOptions ?. readonly || false
56
56
} ) ;
57
57
}
58
58
} ) ;
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import {
30
30
SqliteRun ,
31
31
SqliteStep
32
32
} from '@sqlite-js/driver/worker_threads' ;
33
+ import { BetterSqliteDriverOptions } from './driver.js' ;
33
34
34
35
interface InternalStatement extends SqliteDriverStatement {
35
36
getColumnsSync ( ) : string [ ] ;
@@ -273,10 +274,18 @@ export class BetterSqliteConnection implements SqliteDriverConnection {
273
274
con : bsqlite . Database ;
274
275
private statements = new Map < number , InternalStatement > ( ) ;
275
276
276
- static open ( path : string , options ?: bsqlite . Options ) : BetterSqliteConnection {
277
+ static open (
278
+ path : string ,
279
+ options ?: bsqlite . Options & BetterSqliteDriverOptions
280
+ ) : BetterSqliteConnection {
277
281
const con = new DatabaseConstructor ( path , options ) ;
278
282
con . exec ( 'PRAGMA journal_mode = WAL' ) ;
279
283
con . exec ( 'PRAGMA synchronous = normal' ) ;
284
+ if ( options ?. loadExtensions ) {
285
+ for ( let extension of options . loadExtensions ) {
286
+ con . loadExtension ( extension ) ;
287
+ }
288
+ }
280
289
return new BetterSqliteConnection ( con ) ;
281
290
}
282
291
Original file line number Diff line number Diff line change
1
+ import { BetterSqliteDriverOptions } from './driver.js' ;
1
2
import { BetterSqliteConnection } from './sync-driver.js' ;
2
3
import {
3
4
retriedOpen ,
4
- setupDriverWorker
5
+ setupDriverWorker ,
6
+ ConnectionOptions
5
7
} from '@sqlite-js/driver/worker_threads/setup' ;
6
8
7
9
setupDriverWorker ( {
8
- async openConnection ( options ) {
10
+ async openConnection ( options : ConnectionOptions & BetterSqliteDriverOptions ) {
9
11
return retriedOpen ( ( ) => {
10
12
return BetterSqliteConnection . open ( options . path , options ) ;
11
13
} , 2_000 ) ;
You can’t perform that action at this time.
0 commit comments