@powersync/react-native 1.18.1 → 1.19.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.
@@ -1,5 +1,5 @@
1
1
  import { BaseObserver, DBAdapter, DBAdapterListener, LockContext as PowerSyncLockContext, Transaction as PowerSyncTransaction, DBLockOptions, QueryResult } from '@powersync/common';
2
- import type { QuickSQLiteConnection } from '@journeyapps/react-native-quick-sqlite';
2
+ import type { QuickSQLiteConnection, LockContext as RNQSLockContext } from '@journeyapps/react-native-quick-sqlite';
3
3
  /**
4
4
  * Adapter for React Native Quick SQLite
5
5
  */
@@ -16,7 +16,14 @@ export declare class RNQSDBAdapter extends BaseObserver<DBAdapterListener> imple
16
16
  writeLock<T>(fn: (tx: PowerSyncLockContext) => Promise<T>, options?: DBLockOptions): Promise<T>;
17
17
  writeTransaction<T>(fn: (tx: PowerSyncTransaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
18
18
  execute(query: string, params?: any[]): Promise<import("@journeyapps/react-native-quick-sqlite").QueryResult>;
19
+ /**
20
+ * 'executeRaw' is not implemented in RNQS, this falls back to 'execute'.
21
+ */
22
+ executeRaw(query: string, params?: any[]): Promise<any[][]>;
19
23
  executeBatch(query: string, params?: any[][]): Promise<QueryResult>;
24
+ generateContext<T extends RNQSLockContext>(ctx: T): T & {
25
+ executeRaw: (sql: string, params?: any[]) => Promise<unknown[][]>;
26
+ };
20
27
  /**
21
28
  * This provides a top-level read only execute method which is executed inside a read-lock.
22
29
  * This is necessary since the high level `execute` method uses a write-lock under
@@ -29,20 +29,28 @@ export class RNQSDBAdapter extends BaseObserver {
29
29
  return this.baseDB.close();
30
30
  }
31
31
  readLock(fn, options) {
32
- return this.baseDB.readLock((dbTx) => fn(this.generateDBHelpers(dbTx)), options);
32
+ return this.baseDB.readLock((dbTx) => fn(this.generateDBHelpers(this.generateContext(dbTx))), options);
33
33
  }
34
34
  readTransaction(fn, options) {
35
- return this.baseDB.readTransaction((dbTx) => fn(this.generateDBHelpers(dbTx)), options);
35
+ return this.baseDB.readTransaction((dbTx) => fn(this.generateDBHelpers(this.generateContext(dbTx))), options);
36
36
  }
37
37
  writeLock(fn, options) {
38
- return this.baseDB.writeLock((dbTx) => fn(this.generateDBHelpers(dbTx)), options);
38
+ return this.baseDB.writeLock((dbTx) => fn(this.generateDBHelpers(this.generateContext(dbTx))), options);
39
39
  }
40
40
  writeTransaction(fn, options) {
41
- return this.baseDB.writeTransaction((dbTx) => fn(this.generateDBHelpers(dbTx)), options);
41
+ return this.baseDB.writeTransaction((dbTx) => fn(this.generateDBHelpers(this.generateContext(dbTx))), options);
42
42
  }
43
43
  execute(query, params) {
44
44
  return this.baseDB.execute(query, params);
45
45
  }
46
+ /**
47
+ * 'executeRaw' is not implemented in RNQS, this falls back to 'execute'.
48
+ */
49
+ async executeRaw(query, params) {
50
+ const result = await this.baseDB.execute(query, params);
51
+ const rows = result.rows?._array ?? [];
52
+ return rows.map((row) => Object.values(row));
53
+ }
46
54
  async executeBatch(query, params = []) {
47
55
  const commands = [];
48
56
  for (let i = 0; i < params.length; i++) {
@@ -53,6 +61,17 @@ export class RNQSDBAdapter extends BaseObserver {
53
61
  rowsAffected: result.rowsAffected ? result.rowsAffected : 0
54
62
  };
55
63
  }
64
+ generateContext(ctx) {
65
+ return {
66
+ ...ctx,
67
+ // 'executeRaw' is not implemented in RNQS, this falls back to 'execute'.
68
+ executeRaw: async (sql, params) => {
69
+ const result = await ctx.execute(sql, params);
70
+ const rows = result.rows?._array ?? [];
71
+ return rows.map((row) => Object.values(row));
72
+ }
73
+ };
74
+ }
56
75
  /**
57
76
  * This provides a top-level read only execute method which is executed inside a read-lock.
58
77
  * This is necessary since the high level `execute` method uses a write-lock under
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@powersync/react-native",
3
- "version": "1.18.1",
3
+ "version": "1.19.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"
7
7
  },
8
- "description": "PowerSync - sync Postgres with SQLite in your React Native app for offline-first and real-time data",
8
+ "description": "PowerSync React Native SDK. Sync Postgres, MongoDB or MySQL with SQLite in your React Native app",
9
9
  "main": "./dist/index.js",
10
10
  "module": "./dist/index.js",
11
11
  "types": "./lib/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "homepage": "https://docs.powersync.com/",
26
26
  "peerDependencies": {
27
27
  "@journeyapps/react-native-quick-sqlite": "^2.4.2",
28
- "@powersync/common": "^1.25.0",
28
+ "@powersync/common": "^1.26.0",
29
29
  "react": "*",
30
30
  "react-native": "*"
31
31
  },
@@ -35,8 +35,8 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@powersync/common": "1.25.0",
39
- "@powersync/react": "1.5.1"
38
+ "@powersync/common": "1.26.0",
39
+ "@powersync/react": "1.5.2"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@craftzdog/react-native-buffer": "^6.0.5",