@powersync/web 0.0.0-dev-20260630141119 → 0.0.0-dev-20260708103617
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/powersync.cjs +1 -1
- package/dist/index.umd.js +7821 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/worker/SharedSyncImplementation.umd.js +16139 -0
- package/dist/worker/SharedSyncImplementation.umd.js.map +1 -0
- package/dist/worker/WASQLiteDB.umd.js +17434 -0
- package/dist/worker/WASQLiteDB.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-9af0a7.umd.js +31 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-9af0a7.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-bbf5a9.umd.js +31 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_mc-wa-s-bbf5a9.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-c26e0f.umd.js +31 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqli-c26e0f.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js +31 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_dist_wa-sqlite_mjs.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422.umd.js +3562 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-2fb422.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js +1400 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23.umd.js +2478 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-96fb23.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911.umd.js +1681 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-c89911.umd.js.map +1 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js +1820 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-ec4eb1.umd.js.map +1 -0
- package/lib/package.json +91 -0
- package/lib/src/attachments/IndexDBFileSystemAdapter.js.map +1 -0
- package/lib/{db → src/db}/NavigatorTriggerClaimManager.d.ts +1 -1
- package/lib/src/db/NavigatorTriggerClaimManager.js.map +1 -0
- package/lib/src/db/PowerSyncDatabase.d.ts +78 -0
- package/lib/{db → src/db}/PowerSyncDatabase.js +61 -47
- package/lib/src/db/PowerSyncDatabase.js.map +1 -0
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.d.ts +23 -0
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js +27 -0
- package/lib/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.js.map +1 -0
- package/lib/src/db/adapters/AsyncWebAdapter.d.ts +50 -0
- package/lib/{db → src/db}/adapters/AsyncWebAdapter.js +14 -14
- package/lib/src/db/adapters/AsyncWebAdapter.js.map +1 -0
- package/lib/src/db/adapters/SSRDBAdapter.d.ts +30 -0
- package/lib/src/db/adapters/SSRDBAdapter.js +69 -0
- package/lib/src/db/adapters/SSRDBAdapter.js.map +1 -0
- package/lib/{db → src/db}/adapters/WebDBAdapter.d.ts +1 -1
- package/lib/src/db/adapters/WebDBAdapter.js.map +1 -0
- package/lib/{db → src/db}/adapters/wa-sqlite/ConcurrentConnection.d.ts +4 -3
- package/lib/{db → src/db}/adapters/wa-sqlite/ConcurrentConnection.js +2 -2
- package/lib/src/db/adapters/wa-sqlite/ConcurrentConnection.js.map +1 -0
- package/lib/{db → src/db}/adapters/wa-sqlite/DatabaseClient.d.ts +4 -4
- package/lib/{db → src/db}/adapters/wa-sqlite/DatabaseClient.js +37 -11
- package/lib/src/db/adapters/wa-sqlite/DatabaseClient.js.map +1 -0
- package/lib/{db → src/db}/adapters/wa-sqlite/DatabaseServer.d.ts +5 -5
- package/lib/{db → src/db}/adapters/wa-sqlite/DatabaseServer.js +7 -11
- package/lib/src/db/adapters/wa-sqlite/DatabaseServer.js.map +1 -0
- package/lib/{db → src/db}/adapters/wa-sqlite/RawSqliteConnection.d.ts +12 -23
- package/lib/{db → src/db}/adapters/wa-sqlite/RawSqliteConnection.js +11 -17
- package/lib/src/db/adapters/wa-sqlite/RawSqliteConnection.js.map +1 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +45 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +146 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.js.map +1 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.d.ts +15 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js +22 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.js.map +1 -0
- package/lib/src/db/adapters/wa-sqlite/vfs.d.ts +40 -0
- package/lib/src/db/adapters/wa-sqlite/vfs.js +95 -0
- package/lib/src/db/adapters/wa-sqlite/vfs.js.map +1 -0
- package/lib/src/db/adapters/web-sql-flags.d.ts +92 -0
- package/lib/src/db/adapters/web-sql-flags.js +37 -0
- package/lib/src/db/adapters/web-sql-flags.js.map +1 -0
- package/lib/{db → src/db}/sync/SSRWebStreamingSyncImplementation.d.ts +8 -4
- package/lib/{db → src/db}/sync/SSRWebStreamingSyncImplementation.js +11 -4
- package/lib/src/db/sync/SSRWebStreamingSyncImplementation.js.map +1 -0
- package/lib/{db → src/db}/sync/SharedWebStreamingSyncImplementation.d.ts +14 -13
- package/lib/{db → src/db}/sync/SharedWebStreamingSyncImplementation.js +66 -31
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js.map +1 -0
- package/lib/src/db/sync/WebRemote.d.ts +7 -0
- package/lib/src/db/sync/WebRemote.js +33 -0
- package/lib/src/db/sync/WebRemote.js.map +1 -0
- package/lib/{db → src/db}/sync/WebStreamingSyncImplementation.d.ts +4 -2
- package/lib/{db → src/db}/sync/WebStreamingSyncImplementation.js +2 -3
- package/lib/src/db/sync/WebStreamingSyncImplementation.js.map +1 -0
- package/lib/src/db/sync/userAgent.js.map +1 -0
- package/lib/{index.d.ts → src/index.d.ts} +3 -1
- package/lib/{index.js → src/index.js} +3 -1
- package/lib/src/index.js.map +1 -0
- package/lib/src/shared/navigator.js.map +1 -0
- package/lib/src/shared/tab_close_signal.js.map +1 -0
- package/lib/src/worker/db/MultiDatabaseServer.d.ts +17 -0
- package/lib/{worker → src/worker}/db/MultiDatabaseServer.js +18 -26
- package/lib/src/worker/db/MultiDatabaseServer.js.map +1 -0
- package/lib/src/worker/db/WASQLiteDB.worker.d.ts +4 -0
- package/lib/src/worker/db/WASQLiteDB.worker.js +31 -0
- package/lib/src/worker/db/WASQLiteDB.worker.js.map +1 -0
- package/lib/src/worker/db/open-worker-database.d.ts +14 -0
- package/lib/src/worker/db/open-worker-database.js +53 -0
- package/lib/src/worker/db/open-worker-database.js.map +1 -0
- package/lib/src/worker/sync/AbstractSharedSyncClientProvider.d.ts +19 -0
- package/lib/src/worker/sync/AbstractSharedSyncClientProvider.js.map +1 -0
- package/lib/src/worker/sync/BroadcastLogger.d.ts +47 -0
- package/lib/src/worker/sync/BroadcastLogger.js +129 -0
- package/lib/src/worker/sync/BroadcastLogger.js.map +1 -0
- package/lib/{worker → src/worker}/sync/SharedSyncImplementation.d.ts +15 -11
- package/lib/{worker → src/worker}/sync/SharedSyncImplementation.js +43 -42
- package/lib/src/worker/sync/SharedSyncImplementation.js.map +1 -0
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js +12 -0
- package/lib/src/worker/sync/SharedSyncImplementation.worker.js.map +1 -0
- package/lib/{worker → src/worker}/sync/WorkerClient.d.ts +3 -3
- package/lib/{worker → src/worker}/sync/WorkerClient.js +2 -2
- package/lib/src/worker/sync/WorkerClient.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +29 -22
- package/src/db/NavigatorTriggerClaimManager.ts +1 -1
- package/src/db/PowerSyncDatabase.ts +122 -80
- package/src/db/adapters/AbstractWebPowerSyncDatabaseOpenFactory.ts +47 -0
- package/src/db/adapters/AsyncWebAdapter.ts +26 -17
- package/src/db/adapters/SSRDBAdapter.ts +64 -14
- package/src/db/adapters/WebDBAdapter.ts +1 -1
- package/src/db/adapters/wa-sqlite/ConcurrentConnection.ts +5 -4
- package/src/db/adapters/wa-sqlite/DatabaseClient.ts +56 -20
- package/src/db/adapters/wa-sqlite/DatabaseServer.ts +12 -15
- package/src/db/adapters/wa-sqlite/RawSqliteConnection.ts +24 -41
- package/src/db/adapters/wa-sqlite/WASQLiteOpenFactory.ts +126 -63
- package/src/db/adapters/wa-sqlite/WASQLitePowerSyncDatabaseOpenFactory.ts +24 -0
- package/src/db/adapters/wa-sqlite/vfs.ts +67 -54
- package/src/db/adapters/web-sql-flags.ts +141 -0
- package/src/db/sync/SSRWebStreamingSyncImplementation.ts +22 -4
- package/src/db/sync/SharedWebStreamingSyncImplementation.ts +77 -38
- package/src/db/sync/WebRemote.ts +26 -23
- package/src/db/sync/WebStreamingSyncImplementation.ts +5 -4
- package/src/index.ts +3 -1
- package/src/worker/db/MultiDatabaseServer.ts +25 -41
- package/src/worker/db/WASQLiteDB.worker.ts +35 -0
- package/src/worker/db/open-worker-database.ts +62 -0
- package/src/worker/sync/AbstractSharedSyncClientProvider.ts +10 -4
- package/src/worker/sync/BroadcastLogger.ts +103 -35
- package/src/worker/sync/SharedSyncImplementation.ts +63 -62
- package/src/worker/sync/SharedSyncImplementation.worker.ts +14 -0
- package/src/worker/sync/WorkerClient.ts +4 -4
- package/dist/index.react_native_web.js +0 -1879
- package/dist/index.react_native_web.js.map +0 -1
- package/dist/worker/AccessHandlePoolVFS-BPUHfZME.js +0 -2
- package/dist/worker/AccessHandlePoolVFS-BPUHfZME.js.map +0 -1
- package/dist/worker/FacadeVFS-d1ZDvud7.js +0 -2
- package/dist/worker/FacadeVFS-d1ZDvud7.js.map +0 -1
- package/dist/worker/IDBBatchAtomicVFS-DbkDb777.js +0 -2
- package/dist/worker/IDBBatchAtomicVFS-DbkDb777.js.map +0 -1
- package/dist/worker/OPFSCoopSyncVFS-DRKedN0p.js +0 -2
- package/dist/worker/OPFSCoopSyncVFS-DRKedN0p.js.map +0 -1
- package/dist/worker/OPFSWriteAheadVFS-BzodSqNq.js +0 -2
- package/dist/worker/OPFSWriteAheadVFS-BzodSqNq.js.map +0 -1
- package/dist/worker/mc-wa-sqlite-DiBqIVE5.js +0 -2
- package/dist/worker/mc-wa-sqlite-DiBqIVE5.js.map +0 -1
- package/dist/worker/mc-wa-sqlite-async-DUEhO9ef.js +0 -2
- package/dist/worker/mc-wa-sqlite-async-DUEhO9ef.js.map +0 -1
- package/dist/worker/wa-sqlite-BlSx7-_P.js +0 -2
- package/dist/worker/wa-sqlite-BlSx7-_P.js.map +0 -1
- package/dist/worker/wa-sqlite-async-BdR24Ucf.js +0 -2
- package/dist/worker/wa-sqlite-async-BdR24Ucf.js.map +0 -1
- package/dist/worker/websockets-Q8W_lerF.js +0 -9
- package/dist/worker/websockets-Q8W_lerF.js.map +0 -1
- package/dist/worker/worker.js +0 -7
- package/dist/worker/worker.js.map +0 -1
- package/lib/attachments/IndexDBFileSystemAdapter.js.map +0 -1
- package/lib/db/NavigatorTriggerClaimManager.js.map +0 -1
- package/lib/db/PowerSyncDatabase.d.ts +0 -67
- package/lib/db/PowerSyncDatabase.js.map +0 -1
- package/lib/db/adapters/AsyncWebAdapter.d.ts +0 -32
- package/lib/db/adapters/AsyncWebAdapter.js.map +0 -1
- package/lib/db/adapters/SSRDBAdapter.d.ts +0 -17
- package/lib/db/adapters/SSRDBAdapter.js +0 -37
- package/lib/db/adapters/SSRDBAdapter.js.map +0 -1
- package/lib/db/adapters/WebDBAdapter.js.map +0 -1
- package/lib/db/adapters/options.d.ts +0 -87
- package/lib/db/adapters/options.js +0 -6
- package/lib/db/adapters/options.js.map +0 -1
- package/lib/db/adapters/resolveAndValidateOptions.d.ts +0 -5
- package/lib/db/adapters/resolveAndValidateOptions.js +0 -33
- package/lib/db/adapters/resolveAndValidateOptions.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/ConcurrentConnection.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/DatabaseClient.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/DatabaseServer.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/RawSqliteConnection.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.d.ts +0 -18
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.js +0 -131
- package/lib/db/adapters/wa-sqlite/WASQLiteOpenFactory.js.map +0 -1
- package/lib/db/adapters/wa-sqlite/vfs.d.ts +0 -50
- package/lib/db/adapters/wa-sqlite/vfs.js +0 -77
- package/lib/db/adapters/wa-sqlite/vfs.js.map +0 -1
- package/lib/db/sync/SSRWebStreamingSyncImplementation.js.map +0 -1
- package/lib/db/sync/SharedWebStreamingSyncImplementation.js.map +0 -1
- package/lib/db/sync/WebRemote.d.ts +0 -10
- package/lib/db/sync/WebRemote.js +0 -33
- package/lib/db/sync/WebRemote.js.map +0 -1
- package/lib/db/sync/WebStreamingSyncImplementation.js.map +0 -1
- package/lib/db/sync/userAgent.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/shared/navigator.js.map +0 -1
- package/lib/shared/tab_close_signal.js.map +0 -1
- package/lib/worker/SharedWorkerConnectionRequest.d.ts +0 -5
- package/lib/worker/SharedWorkerConnectionRequest.js +0 -2
- package/lib/worker/SharedWorkerConnectionRequest.js.map +0 -1
- package/lib/worker/client.d.ts +0 -15
- package/lib/worker/client.js +0 -77
- package/lib/worker/client.js.map +0 -1
- package/lib/worker/db/MultiDatabaseServer.d.ts +0 -22
- package/lib/worker/db/MultiDatabaseServer.js.map +0 -1
- package/lib/worker/sync/AbstractSharedSyncClientProvider.d.ts +0 -13
- package/lib/worker/sync/AbstractSharedSyncClientProvider.js.map +0 -1
- package/lib/worker/sync/BroadcastLogger.d.ts +0 -27
- package/lib/worker/sync/BroadcastLogger.js +0 -65
- package/lib/worker/sync/BroadcastLogger.js.map +0 -1
- package/lib/worker/sync/SharedSyncImplementation.js.map +0 -1
- package/lib/worker/sync/WorkerClient.js.map +0 -1
- package/lib/worker/worker.js +0 -34
- package/lib/worker/worker.js.map +0 -1
- package/src/db/adapters/options.ts +0 -100
- package/src/db/adapters/resolveAndValidateOptions.ts +0 -40
- package/src/worker/SharedWorkerConnectionRequest.ts +0 -6
- package/src/worker/client.ts +0 -100
- package/src/worker/worker.ts +0 -38
- /package/dist/{worker/assets/mc-wa-sqlite-async-D6idQS2r.wasm → 2075a31bb151adbb9767.wasm} +0 -0
- /package/dist/{worker/assets/wa-sqlite-XZW__iJk.wasm → 3322bc84de986b63c2cd.wasm} +0 -0
- /package/dist/{worker/assets/mc-wa-sqlite-CnHbhWvs.wasm → 8e97452e297be23b5e50.wasm} +0 -0
- /package/dist/{worker/assets/wa-sqlite-async-rHzzC98y.wasm → fbc178b70d530e8ce02b.wasm} +0 -0
- /package/lib/{attachments → src/attachments}/IndexDBFileSystemAdapter.d.ts +0 -0
- /package/lib/{attachments → src/attachments}/IndexDBFileSystemAdapter.js +0 -0
- /package/lib/{db → src/db}/NavigatorTriggerClaimManager.js +0 -0
- /package/lib/{db → src/db}/adapters/WebDBAdapter.js +0 -0
- /package/lib/{db → src/db}/sync/userAgent.d.ts +0 -0
- /package/lib/{db → src/db}/sync/userAgent.js +0 -0
- /package/lib/{shared → src/shared}/navigator.d.ts +0 -0
- /package/lib/{shared → src/shared}/navigator.js +0 -0
- /package/lib/{shared → src/shared}/tab_close_signal.d.ts +0 -0
- /package/lib/{shared → src/shared}/tab_close_signal.js +0 -0
- /package/lib/{worker → src/worker}/sync/AbstractSharedSyncClientProvider.js +0 -0
- /package/lib/{worker/worker.d.ts → src/worker/sync/SharedSyncImplementation.worker.d.ts} +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AbstractPowerSyncDatabase,
|
|
3
|
+
AbstractPowerSyncDatabaseOpenFactory,
|
|
4
|
+
PowerSyncDatabaseOptions,
|
|
5
|
+
PowerSyncOpenFactoryOptions
|
|
6
|
+
} from '@powersync/common';
|
|
7
|
+
import {
|
|
8
|
+
PowerSyncDatabase,
|
|
9
|
+
WebPowerSyncDatabaseOptions,
|
|
10
|
+
WebPowerSyncFlags,
|
|
11
|
+
resolveWebPowerSyncFlags
|
|
12
|
+
} from '../../db/PowerSyncDatabase.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* {@link WebPowerSyncFlags}
|
|
16
|
+
* Maintaining export for consistency with API from previous versions
|
|
17
|
+
* */
|
|
18
|
+
export interface WebPowerSyncOpenFlags extends WebPowerSyncFlags {}
|
|
19
|
+
|
|
20
|
+
export interface WebPowerSyncOpenFactoryOptions extends PowerSyncOpenFactoryOptions {
|
|
21
|
+
flags?: WebPowerSyncOpenFlags;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Intermediate PowerSync Database Open factory for Web which uses a mock
|
|
26
|
+
* SSR DB Adapter if running on server side.
|
|
27
|
+
* Most SQLite DB implementations only run on client side, this will safely return
|
|
28
|
+
* empty query results in SSR which will allow for generating server partial views.
|
|
29
|
+
*/
|
|
30
|
+
export abstract class AbstractWebPowerSyncDatabaseOpenFactory extends AbstractPowerSyncDatabaseOpenFactory {
|
|
31
|
+
constructor(protected options: WebPowerSyncOpenFactoryOptions) {
|
|
32
|
+
super(options);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
generateOptions(): WebPowerSyncDatabaseOptions {
|
|
36
|
+
return {
|
|
37
|
+
...this.options,
|
|
38
|
+
database: this.openDB(),
|
|
39
|
+
schema: this.schema,
|
|
40
|
+
flags: resolveWebPowerSyncFlags(this.options.flags)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
generateInstance(options: PowerSyncDatabaseOptions): AbstractPowerSyncDatabase {
|
|
45
|
+
return new PowerSyncDatabase(options);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
ConnectionPool,
|
|
3
|
+
DBAdapterDefaultMixin,
|
|
4
|
+
DBAdapterListener,
|
|
5
|
+
DBLockOptions,
|
|
6
|
+
LockContext,
|
|
7
|
+
Mutex,
|
|
8
|
+
Semaphore,
|
|
9
|
+
UnlockFn
|
|
10
|
+
} from '@powersync/common';
|
|
3
11
|
import { SharedConnectionWorker, WebDBAdapter, WebDBAdapterConfiguration } from './WebDBAdapter.js';
|
|
4
12
|
import { DatabaseClient } from './wa-sqlite/DatabaseClient.js';
|
|
5
13
|
|
|
@@ -8,7 +16,7 @@ type PendingListener = { listener: Partial<DBAdapterListener>; closeAfterRegiste
|
|
|
8
16
|
/**
|
|
9
17
|
* A connection pool implementation delegating to another pool opened asynchronnously.
|
|
10
18
|
*/
|
|
11
|
-
|
|
19
|
+
class AsyncConnectionPool implements ConnectionPool {
|
|
12
20
|
protected readonly state: Promise<PoolState>;
|
|
13
21
|
protected resolvedWriter?: DatabaseClient;
|
|
14
22
|
|
|
@@ -18,7 +26,6 @@ export class AsyncDbAdapter extends DBAdapter {
|
|
|
18
26
|
inner: Promise<PoolConnection>,
|
|
19
27
|
readonly name: string
|
|
20
28
|
) {
|
|
21
|
-
super();
|
|
22
29
|
this.state = inner.then((client) => {
|
|
23
30
|
for (const pending of this.pendingListeners) {
|
|
24
31
|
pending.closeAfterRegisteredOnResolvedPool = client.writer.registerListener(pending.listener);
|
|
@@ -74,19 +81,6 @@ export class AsyncDbAdapter extends DBAdapter {
|
|
|
74
81
|
};
|
|
75
82
|
}
|
|
76
83
|
}
|
|
77
|
-
|
|
78
|
-
async shareConnection(): Promise<SharedConnectionWorker> {
|
|
79
|
-
const state = await this.state;
|
|
80
|
-
return state.writer.shareConnection();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
getConfiguration(): WebDBAdapterConfiguration {
|
|
84
|
-
if (this.resolvedWriter) {
|
|
85
|
-
return this.resolvedWriter.getConfiguration();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
throw new Error('AsyncDbAdapter.getConfiguration() can only be called after initializing it.');
|
|
89
|
-
}
|
|
90
84
|
}
|
|
91
85
|
|
|
92
86
|
export interface PoolConnection {
|
|
@@ -196,3 +190,18 @@ function readWritePoolState(writer: DatabaseClient, readers: DatabaseClient[]):
|
|
|
196
190
|
}
|
|
197
191
|
};
|
|
198
192
|
}
|
|
193
|
+
|
|
194
|
+
export class AsyncDbAdapter extends DBAdapterDefaultMixin(AsyncConnectionPool) implements WebDBAdapter {
|
|
195
|
+
async shareConnection(): Promise<SharedConnectionWorker> {
|
|
196
|
+
const state = await this.state;
|
|
197
|
+
return state.writer.shareConnection();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
getConfiguration(): WebDBAdapterConfiguration {
|
|
201
|
+
if (this.resolvedWriter) {
|
|
202
|
+
return this.resolvedWriter.getConfiguration();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
throw new Error('AsyncDbAdapter.getConfiguration() can only be called after initializing it.');
|
|
206
|
+
}
|
|
207
|
+
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
BaseObserver,
|
|
3
|
+
DBAdapterListener,
|
|
4
|
+
DBAdapter,
|
|
5
|
+
DBLockOptions,
|
|
6
|
+
LockContext,
|
|
7
|
+
QueryResult,
|
|
8
|
+
Transaction,
|
|
9
|
+
Mutex,
|
|
10
|
+
timeoutSignal
|
|
11
|
+
} from '@powersync/common';
|
|
3
12
|
|
|
4
|
-
const MOCK_QUERY_RESPONSE:
|
|
5
|
-
rowsAffected: 0
|
|
6
|
-
columnNames: [],
|
|
7
|
-
rawRows: []
|
|
13
|
+
const MOCK_QUERY_RESPONSE: QueryResult = {
|
|
14
|
+
rowsAffected: 0
|
|
8
15
|
};
|
|
9
16
|
|
|
10
17
|
/**
|
|
@@ -12,7 +19,7 @@ const MOCK_QUERY_RESPONSE: RawQueryResult = {
|
|
|
12
19
|
* This adapter will return empty results for queries, which will allow
|
|
13
20
|
* server rendered views to initially generate scaffolding components
|
|
14
21
|
*/
|
|
15
|
-
export class SSRDBAdapter extends DBAdapter {
|
|
22
|
+
export class SSRDBAdapter extends BaseObserver<DBAdapterListener> implements DBAdapter {
|
|
16
23
|
name: string;
|
|
17
24
|
readMutex: Mutex;
|
|
18
25
|
writeMutex: Mutex;
|
|
@@ -27,18 +34,61 @@ export class SSRDBAdapter extends DBAdapter {
|
|
|
27
34
|
close() {}
|
|
28
35
|
|
|
29
36
|
async readLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) {
|
|
30
|
-
return fn(
|
|
37
|
+
return this.readMutex.runExclusive(() => fn(this), timeoutSignal(options?.timeoutMs));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions) {
|
|
41
|
+
return this.readLock(() => fn(this.generateMockTransactionContext()), options);
|
|
31
42
|
}
|
|
32
43
|
|
|
33
44
|
async writeLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) {
|
|
34
|
-
return fn(
|
|
45
|
+
return this.writeMutex.runExclusive(() => fn(this), timeoutSignal(options?.timeoutMs));
|
|
35
46
|
}
|
|
36
47
|
|
|
37
|
-
async
|
|
38
|
-
|
|
48
|
+
async writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions) {
|
|
49
|
+
return this.writeLock(() => fn(this.generateMockTransactionContext()), options);
|
|
50
|
+
}
|
|
39
51
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return MOCK_QUERY_RESPONSE;
|
|
52
|
+
async execute(query: string, params?: any[]): Promise<QueryResult> {
|
|
53
|
+
return this.writeMutex.runExclusive(async () => MOCK_QUERY_RESPONSE);
|
|
43
54
|
}
|
|
55
|
+
|
|
56
|
+
async executeRaw(query: string, params?: any[]): Promise<any[][]> {
|
|
57
|
+
return this.writeMutex.runExclusive(async () => []);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async executeBatch(query: string, params?: any[][]): Promise<QueryResult> {
|
|
61
|
+
return this.writeMutex.runExclusive(async () => MOCK_QUERY_RESPONSE);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async getAll<T>(sql: string, parameters?: any[]): Promise<T[]> {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async getOptional<T>(sql: string, parameters?: any[] | undefined): Promise<T | null> {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async get<T>(sql: string, parameters?: any[] | undefined): Promise<T> {
|
|
73
|
+
throw new Error(`No values are returned in SSR mode`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Generates a mock context for use in read/write transactions.
|
|
78
|
+
* `this` already mocks most of the API, commit and rollback mocks
|
|
79
|
+
* are added here
|
|
80
|
+
*/
|
|
81
|
+
private generateMockTransactionContext(): Transaction {
|
|
82
|
+
return {
|
|
83
|
+
...this,
|
|
84
|
+
commit: async () => {
|
|
85
|
+
return MOCK_QUERY_RESPONSE;
|
|
86
|
+
},
|
|
87
|
+
rollback: async () => {
|
|
88
|
+
return MOCK_QUERY_RESPONSE;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async refreshSchema(): Promise<void> {}
|
|
44
94
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Mutex, UnlockFn } from '@powersync/
|
|
2
|
-
import { RawSqliteConnection
|
|
1
|
+
import { Mutex, UnlockFn } from '@powersync/common';
|
|
2
|
+
import { RawSqliteConnection } from './RawSqliteConnection.js';
|
|
3
|
+
import { ResolvedWASQLiteOpenFactoryOptions } from './WASQLiteOpenFactory.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* A wrapper around a {@link RawSqliteConnection} allowing multiple tabs to access it.
|
|
@@ -32,7 +33,7 @@ export class ConcurrentSqliteConnection {
|
|
|
32
33
|
this.leaseMutex = needsNavigatorLocks ? null : new Mutex();
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
get options():
|
|
36
|
+
get options(): ResolvedWASQLiteOpenFactoryOptions {
|
|
36
37
|
return this.inner.options;
|
|
37
38
|
}
|
|
38
39
|
|
|
@@ -45,7 +46,7 @@ export class ConcurrentSqliteConnection {
|
|
|
45
46
|
const options: LockOptions = { signal: abort };
|
|
46
47
|
|
|
47
48
|
navigator.locks
|
|
48
|
-
.request(`db-lock-${this.options.
|
|
49
|
+
.request(`db-lock-${this.options.dbFilename}`, options, (_) => {
|
|
49
50
|
return new Promise<void>((returnLock) => {
|
|
50
51
|
return resolve(() => {
|
|
51
52
|
returnLock();
|
|
@@ -2,22 +2,23 @@ import {
|
|
|
2
2
|
QueryResult,
|
|
3
3
|
LockContext,
|
|
4
4
|
DBLockOptions,
|
|
5
|
+
DBAdapterListener,
|
|
6
|
+
ConnectionPool,
|
|
5
7
|
SqlExecutor,
|
|
8
|
+
DBGetUtilsDefaultMixin,
|
|
6
9
|
BatchedUpdateNotification,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
queryResultWithoutRows,
|
|
11
|
-
BaseQueryResult
|
|
10
|
+
BaseObserver,
|
|
11
|
+
ConnectionClosedError,
|
|
12
|
+
SQLOpenOptions
|
|
12
13
|
} from '@powersync/common';
|
|
13
14
|
import { SharedConnectionWorker, WebDBAdapterConfiguration } from '../WebDBAdapter.js';
|
|
14
15
|
import { ClientConnectionView } from './DatabaseServer.js';
|
|
16
|
+
import { RawQueryResult } from './RawSqliteConnection.js';
|
|
15
17
|
import * as Comlink from 'comlink';
|
|
16
|
-
import
|
|
17
|
-
import { ConnectionClosedError } from '@powersync/shared-internals';
|
|
18
|
+
import { WorkerDBOpenerOptions } from './WASQLiteOpenFactory.js';
|
|
18
19
|
|
|
19
20
|
export interface OpenWorkerConnection {
|
|
20
|
-
connect(config:
|
|
21
|
+
connect(config: WorkerDBOpenerOptions): Promise<ClientConnectionView>;
|
|
21
22
|
connectToExisting(options: { identifier: string; lockName: string }): Promise<ClientConnectionView>;
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -43,7 +44,10 @@ export interface ClientOptions {
|
|
|
43
44
|
/**
|
|
44
45
|
* A single-connection {@link ConnectionPool} implementation based on a worker connection.
|
|
45
46
|
*/
|
|
46
|
-
export class DatabaseClient<Config extends SQLOpenOptions = WebDBAdapterConfiguration>
|
|
47
|
+
export class DatabaseClient<Config extends SQLOpenOptions = WebDBAdapterConfiguration>
|
|
48
|
+
extends BaseObserver<DBAdapterListener>
|
|
49
|
+
implements ConnectionPool
|
|
50
|
+
{
|
|
47
51
|
#connection: ConnectionState;
|
|
48
52
|
#shareConnectionAbortController = new AbortController();
|
|
49
53
|
#receiveTableUpdates: MessagePort;
|
|
@@ -66,7 +70,9 @@ export class DatabaseClient<Config extends SQLOpenOptions = WebDBAdapterConfigur
|
|
|
66
70
|
port2.onmessage = (event) => {
|
|
67
71
|
const tables = event.data as string[];
|
|
68
72
|
const notification: BatchedUpdateNotification = {
|
|
69
|
-
tables
|
|
73
|
+
tables,
|
|
74
|
+
groupedUpdates: {},
|
|
75
|
+
rawUpdates: []
|
|
70
76
|
};
|
|
71
77
|
this.iterateListeners((l) => {
|
|
72
78
|
l.tablesUpdated && l.tablesUpdated(notification);
|
|
@@ -179,17 +185,16 @@ export class DatabaseClient<Config extends SQLOpenOptions = WebDBAdapterConfigur
|
|
|
179
185
|
}
|
|
180
186
|
|
|
181
187
|
/**
|
|
182
|
-
* A {@link
|
|
188
|
+
* A {@link SqlExecutor} implemented by sending commands to a worker.
|
|
183
189
|
*
|
|
184
190
|
* While an instance is active, it has exclusive access to the underlying database connection (as represented by its
|
|
185
191
|
* token).
|
|
186
192
|
*/
|
|
187
|
-
class
|
|
193
|
+
class ClientSqlExecutor implements SqlExecutor {
|
|
188
194
|
readonly #connection: ConnectionState;
|
|
189
195
|
readonly #token: string;
|
|
190
196
|
|
|
191
197
|
constructor(connection: ConnectionState, token: string) {
|
|
192
|
-
super();
|
|
193
198
|
this.#connection = connection;
|
|
194
199
|
this.#token = token;
|
|
195
200
|
}
|
|
@@ -218,8 +223,37 @@ class ClientLockContext extends LockContext {
|
|
|
218
223
|
}
|
|
219
224
|
}
|
|
220
225
|
|
|
221
|
-
async
|
|
222
|
-
|
|
226
|
+
async execute(query: string, params?: any[] | undefined): Promise<QueryResult> {
|
|
227
|
+
const rs = await this.#executeOnWorker(query, params);
|
|
228
|
+
let rows: QueryResult['rows'] | undefined;
|
|
229
|
+
if (rs.resultSet) {
|
|
230
|
+
const resultSet = rs.resultSet;
|
|
231
|
+
|
|
232
|
+
function rowToJavaScriptObject(row: any[]): Record<string, any> {
|
|
233
|
+
const obj: Record<string, any> = {};
|
|
234
|
+
resultSet.columns.forEach((key, idx) => (obj[key] = row[idx]));
|
|
235
|
+
return obj;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const mapped = resultSet.rows.map(rowToJavaScriptObject);
|
|
239
|
+
|
|
240
|
+
rows = {
|
|
241
|
+
_array: mapped,
|
|
242
|
+
length: mapped.length,
|
|
243
|
+
item: (idx: number) => mapped[idx]
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return {
|
|
248
|
+
rowsAffected: rs.changes,
|
|
249
|
+
insertId: rs.lastInsertRowId,
|
|
250
|
+
rows
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async executeRaw(query: string, params?: any[] | undefined): Promise<any[][]> {
|
|
255
|
+
const rs = await this.#executeOnWorker(query, params);
|
|
256
|
+
return rs.resultSet?.rows ?? [];
|
|
223
257
|
}
|
|
224
258
|
|
|
225
259
|
async #executeOnWorker(query: string, params: any[] | undefined): Promise<RawQueryResult> {
|
|
@@ -229,21 +263,23 @@ class ClientLockContext extends LockContext {
|
|
|
229
263
|
);
|
|
230
264
|
}
|
|
231
265
|
|
|
232
|
-
async executeBatch(query: string, params: any[][] = []): Promise<QueryResult
|
|
266
|
+
async executeBatch(query: string, params: any[][] = []): Promise<QueryResult> {
|
|
233
267
|
const results = await this.maybeTrace(
|
|
234
268
|
(c) => c.executeBatch(this.#token, query, params),
|
|
235
269
|
() => `${query} (batch of ${params.length})`
|
|
236
270
|
);
|
|
237
|
-
const result:
|
|
271
|
+
const result: QueryResult = { insertId: undefined, rowsAffected: 0 };
|
|
238
272
|
for (const source of results) {
|
|
239
|
-
result.insertId = source.
|
|
240
|
-
result.rowsAffected
|
|
273
|
+
result.insertId = source.lastInsertRowId;
|
|
274
|
+
result.rowsAffected += source.changes;
|
|
241
275
|
}
|
|
242
276
|
|
|
243
|
-
return
|
|
277
|
+
return result;
|
|
244
278
|
}
|
|
245
279
|
}
|
|
246
280
|
|
|
281
|
+
class ClientLockContext extends DBGetUtilsDefaultMixin(ClientSqlExecutor) implements LockContext {}
|
|
282
|
+
|
|
247
283
|
interface ConnectionState {
|
|
248
284
|
connection: ClientConnectionView;
|
|
249
285
|
notifyRemoteClosed: AbortController | undefined;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ILogger } from '@powersync/common';
|
|
2
2
|
import { ConcurrentSqliteConnection, ConnectionLeaseToken } from './ConcurrentConnection.js';
|
|
3
|
-
import {
|
|
3
|
+
import { RawQueryResult } from './RawSqliteConnection.js';
|
|
4
4
|
|
|
5
5
|
export interface DatabaseServerOptions {
|
|
6
6
|
inner: ConcurrentSqliteConnection;
|
|
7
7
|
onClose: () => void;
|
|
8
|
-
logger:
|
|
8
|
+
logger: ILogger;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -24,7 +24,7 @@ export class DatabaseServer {
|
|
|
24
24
|
constructor(options: DatabaseServerOptions) {
|
|
25
25
|
this.#options = options;
|
|
26
26
|
const inner = options.inner;
|
|
27
|
-
this.#updateBroadcastChannel = new BroadcastChannel(`${inner.options.
|
|
27
|
+
this.#updateBroadcastChannel = new BroadcastChannel(`${inner.options.dbFilename}-table-updates`);
|
|
28
28
|
|
|
29
29
|
this.#updateBroadcastChannel.onmessage = ({ data }) => {
|
|
30
30
|
this.#pushTableUpdateToClients(data as string[]);
|
|
@@ -85,7 +85,7 @@ export class DatabaseServer {
|
|
|
85
85
|
|
|
86
86
|
// If the client holds a connection lease it hasn't returned, return that now.
|
|
87
87
|
for (const { lease } of connectionLeases.values()) {
|
|
88
|
-
this.#logger.
|
|
88
|
+
this.#logger.debug(`Closing connection lease that hasn't been returned.`);
|
|
89
89
|
await lease.returnLease();
|
|
90
90
|
}
|
|
91
91
|
|
|
@@ -94,10 +94,7 @@ export class DatabaseServer {
|
|
|
94
94
|
if (this.#activeClients.size == 0) {
|
|
95
95
|
await this.forceClose();
|
|
96
96
|
} else {
|
|
97
|
-
this.#logger.
|
|
98
|
-
level: LogLevels.debug,
|
|
99
|
-
message: 'Keeping underlying connection active since its used by other clients.'
|
|
100
|
-
});
|
|
97
|
+
this.#logger.debug('Keeping underlying connection active since its used by other clients.');
|
|
101
98
|
}
|
|
102
99
|
}
|
|
103
100
|
};
|
|
@@ -136,9 +133,9 @@ export class DatabaseServer {
|
|
|
136
133
|
try {
|
|
137
134
|
if (lease.write) {
|
|
138
135
|
// Collect update hooks invoked while the client had the write connection.
|
|
139
|
-
const {
|
|
140
|
-
if (
|
|
141
|
-
const updatedTables: string[] = JSON.parse(
|
|
136
|
+
const { resultSet } = await lease.lease.use((conn) => conn.execute(`SELECT powersync_update_hooks('get')`));
|
|
137
|
+
if (resultSet) {
|
|
138
|
+
const updatedTables: string[] = JSON.parse(resultSet.rows[0][0] as string);
|
|
142
139
|
if (updatedTables.length) {
|
|
143
140
|
this.#updateBroadcastChannel.postMessage(updatedTables);
|
|
144
141
|
this.#pushTableUpdateToClients(updatedTables);
|
|
@@ -172,7 +169,7 @@ export class DatabaseServer {
|
|
|
172
169
|
}
|
|
173
170
|
|
|
174
171
|
async forceClose() {
|
|
175
|
-
this.#logger.
|
|
172
|
+
this.#logger.debug(`Closing connection to ${this.#inner.options}.`);
|
|
176
173
|
const connection = this.#inner;
|
|
177
174
|
this.#options.onClose();
|
|
178
175
|
this.#updateBroadcastChannel.close();
|
|
@@ -193,8 +190,8 @@ export interface ClientConnectionView {
|
|
|
193
190
|
* give other clients access to the database afterwards.
|
|
194
191
|
*/
|
|
195
192
|
requestAccess(write: boolean, timeoutMs?: number): Promise<string>;
|
|
196
|
-
execute(token: string, sql: string, params: any[] | undefined): Promise<
|
|
197
|
-
executeBatch(token: string, sql: string, params: any[][]): Promise<
|
|
193
|
+
execute(token: string, sql: string, params: any[] | undefined): Promise<RawQueryResult>;
|
|
194
|
+
executeBatch(token: string, sql: string, params: any[][]): Promise<RawQueryResult[]>;
|
|
198
195
|
completeAccess(token: string): Promise<void>;
|
|
199
196
|
|
|
200
197
|
/**
|
|
@@ -1,28 +1,18 @@
|
|
|
1
1
|
import { Factory as WaSqliteFactory, SQLITE_ROW } from '@journeyapps/wa-sqlite';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { RawQueryResult, SqliteValue } from '@powersync/common';
|
|
6
|
-
|
|
7
|
-
export interface RawWebResult extends Required<RawQueryResult> {
|
|
8
|
-
autocommit: boolean;
|
|
9
|
-
}
|
|
3
|
+
import { loadModuleAndVfs } from './vfs.js';
|
|
4
|
+
import { ResolvedWASQLiteOpenFactoryOptions } from './WASQLiteOpenFactory.js';
|
|
10
5
|
|
|
11
6
|
export interface RawResultSet {
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
columns: string[];
|
|
8
|
+
rows: SQLiteCompatibleType[][];
|
|
14
9
|
}
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
readonly: boolean;
|
|
22
|
-
vfs: WASQLiteVFS;
|
|
23
|
-
encryptionKey: string | undefined;
|
|
24
|
-
temporaryStorage: TemporaryStorageOption;
|
|
25
|
-
cacheSizeKb: number;
|
|
11
|
+
export interface RawQueryResult {
|
|
12
|
+
changes: number;
|
|
13
|
+
lastInsertRowId: number;
|
|
14
|
+
autocommit: boolean;
|
|
15
|
+
resultSet: RawResultSet | undefined;
|
|
26
16
|
}
|
|
27
17
|
|
|
28
18
|
/**
|
|
@@ -37,11 +27,8 @@ export class RawSqliteConnection {
|
|
|
37
27
|
* The `sqlite3*` connection pointer.
|
|
38
28
|
*/
|
|
39
29
|
private db: number = 0;
|
|
40
|
-
private _moduleFactory: WASQLiteModuleFactory;
|
|
41
30
|
|
|
42
|
-
constructor(readonly options:
|
|
43
|
-
this._moduleFactory = DEFAULT_MODULE_FACTORIES[this.options.vfs];
|
|
44
|
-
}
|
|
31
|
+
constructor(readonly options: ResolvedWASQLiteOpenFactoryOptions) {}
|
|
45
32
|
|
|
46
33
|
get isOpen(): boolean {
|
|
47
34
|
return this.db != 0;
|
|
@@ -50,8 +37,8 @@ export class RawSqliteConnection {
|
|
|
50
37
|
async init() {
|
|
51
38
|
const api = (this._sqliteAPI = await this.openSQLiteAPI());
|
|
52
39
|
this.db = await api.open_v2(
|
|
53
|
-
this.options.
|
|
54
|
-
this.options.
|
|
40
|
+
this.options.dbFilename,
|
|
41
|
+
this.options.isReadOnly ? 1 /* SQLITE_OPEN_READONLY */ : 6 /* SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE */
|
|
55
42
|
);
|
|
56
43
|
await this.executeRaw(`PRAGMA temp_store = ${this.options.temporaryStorage};`);
|
|
57
44
|
if (this.options.encryptionKey) {
|
|
@@ -64,10 +51,7 @@ export class RawSqliteConnection {
|
|
|
64
51
|
}
|
|
65
52
|
|
|
66
53
|
private async openSQLiteAPI(): Promise<SQLiteAPI> {
|
|
67
|
-
const { module, vfs } = await this.
|
|
68
|
-
dbFileName: this.options.filename,
|
|
69
|
-
encryptionKey: this.options.encryptionKey
|
|
70
|
-
});
|
|
54
|
+
const { module, vfs } = await loadModuleAndVfs(this.options);
|
|
71
55
|
const sqlite3 = WaSqliteFactory(module);
|
|
72
56
|
sqlite3.vfs_register(vfs, true);
|
|
73
57
|
/**
|
|
@@ -79,7 +63,7 @@ export class RawSqliteConnection {
|
|
|
79
63
|
* Create the multiple cipher vfs if an encryption key is provided
|
|
80
64
|
*/
|
|
81
65
|
if (this.options.encryptionKey) {
|
|
82
|
-
const createResult = module.ccall('sqlite3mc_vfs_create', 'int', ['string', 'int'], [this.options.
|
|
66
|
+
const createResult = module.ccall('sqlite3mc_vfs_create', 'int', ['string', 'int'], [this.options.dbFilename, 1]);
|
|
83
67
|
if (createResult !== 0) {
|
|
84
68
|
throw new Error('Failed to create multiple cipher vfs, Database encryption will not work');
|
|
85
69
|
}
|
|
@@ -103,12 +87,12 @@ export class RawSqliteConnection {
|
|
|
103
87
|
return this.requireSqlite().get_autocommit(this.db) != 0;
|
|
104
88
|
}
|
|
105
89
|
|
|
106
|
-
async execute(sql: string, bindings?: any[]): Promise<
|
|
90
|
+
async execute(sql: string, bindings?: any[]): Promise<RawQueryResult> {
|
|
107
91
|
const resultSet = await this.executeSingleStatementRaw(sql, bindings);
|
|
108
92
|
return this.wrapQueryResults(this.requireSqlite(), resultSet);
|
|
109
93
|
}
|
|
110
94
|
|
|
111
|
-
async executeBatch(sql: string, bindings: any[][]): Promise<
|
|
95
|
+
async executeBatch(sql: string, bindings: any[][]): Promise<RawQueryResult[]> {
|
|
112
96
|
const results = [];
|
|
113
97
|
const api = this.requireSqlite();
|
|
114
98
|
for await (const stmt of api.statements(this.db, sql)) {
|
|
@@ -126,22 +110,21 @@ export class RawSqliteConnection {
|
|
|
126
110
|
return results;
|
|
127
111
|
}
|
|
128
112
|
|
|
129
|
-
private wrapQueryResults(api: SQLiteAPI,
|
|
113
|
+
private wrapQueryResults(api: SQLiteAPI, rs: RawResultSet | undefined): RawQueryResult {
|
|
130
114
|
return {
|
|
131
|
-
|
|
132
|
-
|
|
115
|
+
changes: api.changes(this.db),
|
|
116
|
+
lastInsertRowId: api.last_insert_id(this.db),
|
|
133
117
|
autocommit: api.get_autocommit(this.db) != 0,
|
|
134
|
-
|
|
135
|
-
columnNames
|
|
118
|
+
resultSet: rs
|
|
136
119
|
};
|
|
137
120
|
}
|
|
138
121
|
|
|
139
122
|
/**
|
|
140
123
|
* This executes a single statement using SQLite3 and returns the results as a {@link RawResultSet}.
|
|
141
124
|
*/
|
|
142
|
-
private async executeSingleStatementRaw(sql: string, bindings?: any[]): Promise<RawResultSet> {
|
|
125
|
+
private async executeSingleStatementRaw(sql: string, bindings?: any[]): Promise<RawResultSet | undefined> {
|
|
143
126
|
const results = await this.executeRaw(sql, bindings);
|
|
144
|
-
return results.length ? results[0] :
|
|
127
|
+
return results.length ? results[0] : undefined;
|
|
145
128
|
}
|
|
146
129
|
|
|
147
130
|
async executeRaw(sql: string, bindings?: any[]): Promise<RawResultSet[]> {
|
|
@@ -151,7 +134,7 @@ export class RawSqliteConnection {
|
|
|
151
134
|
let columns;
|
|
152
135
|
|
|
153
136
|
const rs = await this.stepThroughStatement(api, stmt, bindings ?? [], columns);
|
|
154
|
-
columns = rs.
|
|
137
|
+
columns = rs.columns;
|
|
155
138
|
if (columns.length) {
|
|
156
139
|
results.push(rs);
|
|
157
140
|
}
|
|
@@ -193,7 +176,7 @@ export class RawSqliteConnection {
|
|
|
193
176
|
}
|
|
194
177
|
|
|
195
178
|
knownColumns ??= api.column_names(stmt);
|
|
196
|
-
return {
|
|
179
|
+
return { columns: knownColumns, rows };
|
|
197
180
|
}
|
|
198
181
|
|
|
199
182
|
async close() {
|