@powersync/web 1.15.1 → 1.16.0

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/dist/index.umd.js CHANGED
@@ -33780,7 +33780,8 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
33780
33780
  };
33781
33781
  }
33782
33782
  this.dbGetHelpers = this.generateDBHelpers({
33783
- execute: (query, params) => this.acquireLock(() => this._execute(query, params))
33783
+ execute: (query, params) => this.acquireLock(() => this._execute(query, params)),
33784
+ executeRaw: (query, params) => this.acquireLock(() => this._executeRaw(query, params))
33784
33785
  });
33785
33786
  this.initPromise = this._init();
33786
33787
  }
@@ -33838,6 +33839,9 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
33838
33839
  async execute(query, params) {
33839
33840
  return this.writeLock((ctx) => ctx.execute(query, params));
33840
33841
  }
33842
+ async executeRaw(query, params) {
33843
+ return this.writeLock((ctx) => ctx.executeRaw(query, params));
33844
+ }
33841
33845
  async executeBatch(query, params) {
33842
33846
  return this.writeLock((ctx) => this._executeBatch(query, params));
33843
33847
  }
@@ -33864,11 +33868,11 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
33864
33868
  }
33865
33869
  async readLock(fn, options) {
33866
33870
  await this.waitForInitialized();
33867
- return this.acquireLock(async () => fn(this.generateDBHelpers({ execute: this._execute })));
33871
+ return this.acquireLock(async () => fn(this.generateDBHelpers({ execute: this._execute, executeRaw: this._executeRaw })));
33868
33872
  }
33869
33873
  async writeLock(fn, options) {
33870
33874
  await this.waitForInitialized();
33871
- return this.acquireLock(async () => fn(this.generateDBHelpers({ execute: this._execute })));
33875
+ return this.acquireLock(async () => fn(this.generateDBHelpers({ execute: this._execute, executeRaw: this._executeRaw })));
33872
33876
  }
33873
33877
  acquireLock(callback) {
33874
33878
  return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_2__.getNavigatorLocks)().request(`db-lock-${this._dbIdentifier}`, callback);
@@ -33965,6 +33969,13 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
33965
33969
  }
33966
33970
  };
33967
33971
  };
33972
+ /**
33973
+ * Wraps the worker executeRaw function, awaiting for it to be available
33974
+ */
33975
+ _executeRaw = async (sql, bindings) => {
33976
+ await this.waitForInitialized();
33977
+ return await this.baseDB.executeRaw(sql, bindings);
33978
+ };
33968
33979
  /**
33969
33980
  * Wraps the worker executeBatch function, awaiting for it to be available
33970
33981
  */
@@ -34032,6 +34043,9 @@ class SSRDBAdapter extends _powersync_common__WEBPACK_IMPORTED_MODULE_0__.BaseOb
34032
34043
  async execute(query, params) {
34033
34044
  return this.writeMutex.runExclusive(async () => MOCK_QUERY_RESPONSE);
34034
34045
  }
34046
+ async executeRaw(query, params) {
34047
+ return this.writeMutex.runExclusive(async () => []);
34048
+ }
34035
34049
  async executeBatch(query, params) {
34036
34050
  return this.writeMutex.runExclusive(async () => MOCK_QUERY_RESPONSE);
34037
34051
  }
@@ -34154,6 +34168,9 @@ class WorkerWrappedAsyncDatabaseConnection {
34154
34168
  execute(sql, params) {
34155
34169
  return this.baseConnection.execute(sql, params);
34156
34170
  }
34171
+ executeRaw(sql, params) {
34172
+ return this.baseConnection.executeRaw(sql, params);
34173
+ }
34157
34174
  executeBatch(sql, params) {
34158
34175
  return this.baseConnection.executeBatch(sql, params);
34159
34176
  }
@@ -34374,8 +34391,8 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
34374
34391
  await this.openDB();
34375
34392
  this.registerBroadcastListeners();
34376
34393
  await this.executeSingleStatement(`PRAGMA temp_store = ${this.options.temporaryStorage};`);
34377
- await this.executeSingleStatement(`PRAGMA cache_size = -${this.options.cacheSizeKb};`);
34378
34394
  await this.executeEncryptionPragma();
34395
+ await this.executeSingleStatement(`PRAGMA cache_size = -${this.options.cacheSizeKb};`);
34379
34396
  this.sqliteAPI.update_hook(this.dbP, (updateType, dbName, tableName) => {
34380
34397
  if (!tableName) {
34381
34398
  return;
@@ -34461,6 +34478,11 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
34461
34478
  return this.executeSingleStatement(sql, bindings);
34462
34479
  });
34463
34480
  }
34481
+ async executeRaw(sql, bindings) {
34482
+ return this.acquireExecuteLock(async () => {
34483
+ return this.executeSingleStatementRaw(sql, bindings);
34484
+ });
34485
+ }
34464
34486
  async close() {
34465
34487
  this.broadcastChannel?.close();
34466
34488
  await this.sqliteAPI.close(this.dbP);
@@ -34481,6 +34503,35 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
34481
34503
  * This executes a single statement using SQLite3.
34482
34504
  */
34483
34505
  async executeSingleStatement(sql, bindings) {
34506
+ const results = await this._execute(sql, bindings);
34507
+ const rows = [];
34508
+ for (const resultSet of results) {
34509
+ for (const row of resultSet.rows) {
34510
+ const outRow = {};
34511
+ resultSet.columns.forEach((key, index) => {
34512
+ outRow[key] = row[index];
34513
+ });
34514
+ rows.push(outRow);
34515
+ }
34516
+ }
34517
+ const result = {
34518
+ insertId: this.sqliteAPI.last_insert_id(this.dbP),
34519
+ rowsAffected: this.sqliteAPI.changes(this.dbP),
34520
+ rows: {
34521
+ _array: rows,
34522
+ length: rows.length
34523
+ }
34524
+ };
34525
+ return result;
34526
+ }
34527
+ /**
34528
+ * This executes a single statement using SQLite3 and returns the results as an array of arrays.
34529
+ */
34530
+ async executeSingleStatementRaw(sql, bindings) {
34531
+ const results = await this._execute(sql, bindings);
34532
+ return results.flatMap((resultset) => resultset.rows.map((row) => resultset.columns.map((_, index) => row[index])));
34533
+ }
34534
+ async _execute(sql, bindings) {
34484
34535
  const results = [];
34485
34536
  for await (const stmt of this.sqliteAPI.statements(this.dbP, sql)) {
34486
34537
  let columns;
@@ -34511,25 +34562,7 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
34511
34562
  break;
34512
34563
  }
34513
34564
  }
34514
- const rows = [];
34515
- for (const resultSet of results) {
34516
- for (const row of resultSet.rows) {
34517
- const outRow = {};
34518
- resultSet.columns.forEach((key, index) => {
34519
- outRow[key] = row[index];
34520
- });
34521
- rows.push(outRow);
34522
- }
34523
- }
34524
- const result = {
34525
- insertId: this.sqliteAPI.last_insert_id(this.dbP),
34526
- rowsAffected: this.sqliteAPI.changes(this.dbP),
34527
- rows: {
34528
- _array: rows,
34529
- length: rows.length
34530
- }
34531
- };
34532
- return result;
34565
+ return results;
34533
34566
  }
34534
34567
  }
34535
34568