@powersync/react-native 1.30.2 → 1.32.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.js CHANGED
@@ -19300,15 +19300,9 @@ function uint8ArrayToArrayBuffer(array) {
19300
19300
  }
19301
19301
  }
19302
19302
 
19303
- /**
19304
- * Adapter for React Native Quick SQLite
19305
- */
19306
- class RNQSDBAdapter extends common.BaseObserver {
19303
+ class RNQSConnectionPool extends common.BaseObserver {
19307
19304
  baseDB;
19308
19305
  name;
19309
- getAll;
19310
- getOptional;
19311
- get;
19312
19306
  constructor(baseDB, name) {
19313
19307
  super();
19314
19308
  this.baseDB = baseDB;
@@ -19317,41 +19311,48 @@ class RNQSDBAdapter extends common.BaseObserver {
19317
19311
  baseDB.registerTablesChangedHook((update) => {
19318
19312
  this.iterateListeners((cb) => cb.tablesUpdated?.(update));
19319
19313
  });
19320
- const topLevelUtils = this.generateDBHelpers({
19321
- // Arrow function binds `this` for use in readOnlyExecute
19322
- execute: (sql, params) => this.readOnlyExecute(sql, params)
19323
- });
19324
- // Only assigning get helpers
19325
- this.getAll = topLevelUtils.getAll;
19326
- this.getOptional = topLevelUtils.getOptional;
19327
- this.get = topLevelUtils.get;
19328
19314
  }
19329
19315
  close() {
19330
19316
  return this.baseDB.close();
19331
19317
  }
19332
19318
  readLock(fn, options) {
19333
- return this.baseDB.readLock((dbTx) => fn(this.generateDBHelpers(this.generateContext(dbTx))), options);
19334
- }
19335
- readTransaction(fn, options) {
19336
- return this.baseDB.readTransaction((dbTx) => fn(this.generateDBHelpers(this.generateContext(dbTx))), options);
19319
+ return this.baseDB.readLock((dbTx) => fn(this.generateContext(dbTx)), options);
19337
19320
  }
19338
19321
  writeLock(fn, options) {
19339
- return this.baseDB.writeLock((dbTx) => fn(this.generateDBHelpers(this.generateContext(dbTx))), options);
19322
+ return this.baseDB.writeLock((dbTx) => fn(this.generateContext(dbTx)), options);
19323
+ }
19324
+ generateContext(ctx) {
19325
+ return new QuickSqliteContext(ctx);
19326
+ }
19327
+ async refreshSchema() {
19328
+ await this.baseDB.refreshSchema();
19340
19329
  }
19341
- writeTransaction(fn, options) {
19342
- return this.baseDB.writeTransaction((dbTx) => fn(this.generateDBHelpers(this.generateContext(dbTx))), options);
19330
+ }
19331
+ class QuickSqliteExecutor {
19332
+ context;
19333
+ constructor(context) {
19334
+ this.context = context;
19343
19335
  }
19344
19336
  execute(query, params) {
19345
- return this.baseDB.execute(query, params);
19337
+ return this.context.execute(query, params);
19346
19338
  }
19347
19339
  /**
19348
19340
  * 'executeRaw' is not implemented in RNQS, this falls back to 'execute'.
19349
19341
  */
19350
19342
  async executeRaw(query, params) {
19351
- const result = await this.baseDB.execute(query, params);
19343
+ const result = await this.context.execute(query, params);
19352
19344
  const rows = result.rows?._array ?? [];
19353
19345
  return rows.map((row) => Object.values(row));
19354
19346
  }
19347
+ }
19348
+ class QuickSqliteContext extends common.DBGetUtilsDefaultMixin(QuickSqliteExecutor) {
19349
+ }
19350
+ /**
19351
+ * Adapter for React Native Quick SQLite
19352
+ */
19353
+ class RNQSDBAdapter extends common.DBAdapterDefaultMixin(RNQSConnectionPool) {
19354
+ // We don't want the default implementation here, RNQS does not support executeBatch for lock contexts so that would
19355
+ // be less efficient.
19355
19356
  async executeBatch(query, params = []) {
19356
19357
  const commands = [];
19357
19358
  for (let i = 0; i < params.length; i++) {
@@ -19362,64 +19363,6 @@ class RNQSDBAdapter extends common.BaseObserver {
19362
19363
  rowsAffected: result.rowsAffected ? result.rowsAffected : 0
19363
19364
  };
19364
19365
  }
19365
- generateContext(ctx) {
19366
- return {
19367
- ...ctx,
19368
- // 'executeRaw' is not implemented in RNQS, this falls back to 'execute'.
19369
- executeRaw: async (sql, params) => {
19370
- const result = await ctx.execute(sql, params);
19371
- const rows = result.rows?._array ?? [];
19372
- return rows.map((row) => Object.values(row));
19373
- }
19374
- };
19375
- }
19376
- /**
19377
- * This provides a top-level read only execute method which is executed inside a read-lock.
19378
- * This is necessary since the high level `execute` method uses a write-lock under
19379
- * the hood. Helper methods such as `get`, `getAll` and `getOptional` are read only,
19380
- * and should use this method.
19381
- */
19382
- readOnlyExecute(sql, params) {
19383
- return this.baseDB.readLock((ctx) => ctx.execute(sql, params));
19384
- }
19385
- /**
19386
- * Adds DB get utils to lock contexts and transaction contexts
19387
- * @param tx
19388
- * @returns
19389
- */
19390
- generateDBHelpers(tx) {
19391
- return {
19392
- ...tx,
19393
- /**
19394
- * Execute a read-only query and return results
19395
- */
19396
- getAll: async (sql, parameters) => {
19397
- const res = await tx.execute(sql, parameters);
19398
- return res.rows?._array ?? [];
19399
- },
19400
- /**
19401
- * Execute a read-only query and return the first result, or null if the ResultSet is empty.
19402
- */
19403
- getOptional: async (sql, parameters) => {
19404
- const res = await tx.execute(sql, parameters);
19405
- return res.rows?.item(0) ?? null;
19406
- },
19407
- /**
19408
- * Execute a read-only query and return the first result, error if the ResultSet is empty.
19409
- */
19410
- get: async (sql, parameters) => {
19411
- const res = await tx.execute(sql, parameters);
19412
- const first = res.rows?.item(0);
19413
- if (!first) {
19414
- throw new Error('Result set is empty');
19415
- }
19416
- return first;
19417
- }
19418
- };
19419
- }
19420
- async refreshSchema() {
19421
- await this.baseDB.refreshSchema();
19422
- }
19423
19366
  }
19424
19367
 
19425
19368
  /**