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 {
1212import { WorkerDriverConnection } from '@sqlite-js/driver/worker_threads' ;
1313import type * as bsqlite from 'better-sqlite3' ;
1414
15- export interface BetterSqliteDriverOptions
16- extends ConnectionPoolOptions ,
17- bsqlite . Options {
15+ export interface BetterSqliteDriverOptions extends ConnectionPoolOptions {
1816 /**
1917 * Specify a custom path to a worker script, to customize the loading process.
2018 */
2119 workerPath ?: string | URL ;
20+
21+ loadExtensions ?: string [ ] ;
2222}
2323
2424export class BetterSqliteDriver implements SqliteDriverConnectionPool {
@@ -52,7 +52,7 @@ export class BetterSqliteDriver implements SqliteDriverConnectionPool {
5252 async openConnection ( connectionOptions ) {
5353 return new WorkerDriverConnection ( workerPath , path , {
5454 ...options ,
55- readonly : ( options ?. readonly ?? connectionOptions ?. readonly ) || false
55+ readonly : connectionOptions ?. readonly || false
5656 } ) ;
5757 }
5858 } ) ;
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import {
3030 SqliteRun ,
3131 SqliteStep
3232} from '@sqlite-js/driver/worker_threads' ;
33+ import { BetterSqliteDriverOptions } from './driver.js' ;
3334
3435interface InternalStatement extends SqliteDriverStatement {
3536 getColumnsSync ( ) : string [ ] ;
@@ -273,10 +274,18 @@ export class BetterSqliteConnection implements SqliteDriverConnection {
273274 con : bsqlite . Database ;
274275 private statements = new Map < number , InternalStatement > ( ) ;
275276
276- static open ( path : string , options ?: bsqlite . Options ) : BetterSqliteConnection {
277+ static open (
278+ path : string ,
279+ options ?: bsqlite . Options & BetterSqliteDriverOptions
280+ ) : BetterSqliteConnection {
277281 const con = new DatabaseConstructor ( path , options ) ;
278282 con . exec ( 'PRAGMA journal_mode = WAL' ) ;
279283 con . exec ( 'PRAGMA synchronous = normal' ) ;
284+ if ( options ?. loadExtensions ) {
285+ for ( let extension of options . loadExtensions ) {
286+ con . loadExtension ( extension ) ;
287+ }
288+ }
280289 return new BetterSqliteConnection ( con ) ;
281290 }
282291
Original file line number Diff line number Diff line change 1+ import { BetterSqliteDriverOptions } from './driver.js' ;
12import { BetterSqliteConnection } from './sync-driver.js' ;
23import {
34 retriedOpen ,
4- setupDriverWorker
5+ setupDriverWorker ,
6+ ConnectionOptions
57} from '@sqlite-js/driver/worker_threads/setup' ;
68
79setupDriverWorker ( {
8- async openConnection ( options ) {
10+ async openConnection ( options : ConnectionOptions & BetterSqliteDriverOptions ) {
911 return retriedOpen ( ( ) => {
1012 return BetterSqliteConnection . open ( options . path , options ) ;
1113 } , 2_000 ) ;
You can’t perform that action at this time.
0 commit comments