Skip to content

Commit bd62cf4

Browse files
committed
Use default import
1 parent ac9b884 commit bd62cf4

File tree

5 files changed

+14
-20
lines changed

5 files changed

+14
-20
lines changed

packages/node/rollup.config.mjs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ const plugin = () => {
99
} else {
1010
return await this.resolve(source, importer, options);
1111
}
12-
},
13-
resolveImportMeta: (property) => {
14-
if (property == 'isBundlingToCommonJs') {
15-
return 'true';
16-
}
17-
18-
return null;
1912
}
2013
};
2114
};

packages/node/src/db/BetterSqliteWorker.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { Database } from 'better-sqlite3';
22
import { AsyncDatabase, AsyncDatabaseOpenOptions } from './AsyncDatabase.js';
33
import { PowerSyncWorkerOptions } from './SqliteWorker.js';
44
import { threadId } from 'node:worker_threads';
5-
import { dynamicImport } from '../utils/modules.js';
65

76
class BlockingAsyncDatabase implements AsyncDatabase {
87
private readonly db: Database;
@@ -63,8 +62,8 @@ class BlockingAsyncDatabase implements AsyncDatabase {
6362
}
6463
}
6564

66-
export async function openDatabase(worker: PowerSyncWorkerOptions, options: AsyncDatabaseOpenOptions, pkg: string) {
67-
const BetterSQLite3Database: typeof Database = (await dynamicImport(pkg)).default;
65+
export async function openDatabase(worker: PowerSyncWorkerOptions, options: AsyncDatabaseOpenOptions) {
66+
const BetterSQLite3Database = await worker.loadBetterSqlite3();
6867
const baseDB = new BetterSQLite3Database(options.path);
6968
baseDB.pragma('journal_mode = WAL');
7069
baseDB.loadExtension(worker.extensionPath(), 'sqlite3_powersync_init');

packages/node/src/db/SqliteWorker.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { openDatabase as openBetterSqliteDatabase } from './BetterSqliteWorker.j
77
import { openDatabase as openNodeDatabase } from './NodeSqliteWorker.js';
88
import { AsyncDatabase, AsyncDatabaseOpener, AsyncDatabaseOpenOptions } from './AsyncDatabase.js';
99
import { isBundledToCommonJs } from '../utils/modules.js';
10+
import { dynamicImport } from '../utils/modules.js';
1011

1112
export interface PowerSyncWorkerOptions {
1213
/**
@@ -15,6 +16,11 @@ export interface PowerSyncWorkerOptions {
1516
* @returns The absolute path of the PowerSync SQLite core extensions library.
1617
*/
1718
extensionPath: () => string;
19+
20+
/**
21+
* A function that returns the `Database` constructor from the `better-sqlite3` package.
22+
*/
23+
loadBetterSqlite3: () => Promise<any>;
1824
}
1925

2026
export function startPowerSyncWorker(options?: Partial<PowerSyncWorkerOptions>) {
@@ -43,6 +49,10 @@ export function startPowerSyncWorker(options?: Partial<PowerSyncWorkerOptions>)
4349

4450
return resolved;
4551
},
52+
async loadBetterSqlite3() {
53+
const module = await dynamicImport('better-sqlite3');
54+
return module.default;
55+
},
4656
...options
4757
};
4858

@@ -62,7 +72,7 @@ class DatabaseOpenHelper implements AsyncDatabaseOpener {
6272
const implementation = options.implementation;
6373
switch (implementation.type) {
6474
case 'better-sqlite3':
65-
database = await openBetterSqliteDatabase(this.options, options, implementation.package ?? 'better-sqlite3');
75+
database = await openBetterSqliteDatabase(this.options, options);
6676
break;
6777
case 'node:sqlite':
6878
database = await openNodeDatabase(this.options, options);

packages/node/src/db/WorkerConnectionPool.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ export type BetterSQLite3Transaction = Transaction & BetterSQLite3LockContext;
2929
const READ_CONNECTIONS = 5;
3030

3131
const defaultDatabaseImplementation: NodeDatabaseImplementation = {
32-
type: 'better-sqlite3',
33-
package: 'better-sqlite3'
32+
type: 'better-sqlite3'
3433
};
3534

3635
/**

packages/node/src/db/options.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ export type WorkerOpener = (...args: ConstructorParameters<typeof Worker>) => In
88
*/
99
export interface BetterSqlite3Options {
1010
type: 'better-sqlite3';
11-
/**
12-
* The package import to resolve for better-sqlite3.
13-
*
14-
* While this defaults to `better-sqlite3`, this allows using forked better-sqlite3 packages, such as those used for
15-
* encryption.
16-
*/
17-
package?: string;
1811
}
1912

2013
/**

0 commit comments

Comments
 (0)