@powersync/op-sqlite 0.0.0-dev-20250207081035 → 0.0.0-dev-20250319141441

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.
Files changed (33) hide show
  1. package/README.md +4 -23
  2. package/android/build.gradle +1 -1
  3. package/lib/commonjs/db/OPSQLiteConnection.js +3 -0
  4. package/lib/commonjs/db/OPSQLiteConnection.js.map +1 -1
  5. package/lib/commonjs/db/OPSqliteAdapter.js +14 -4
  6. package/lib/commonjs/db/OPSqliteAdapter.js.map +1 -1
  7. package/lib/commonjs/db/SqliteOptions.js +8 -2
  8. package/lib/commonjs/db/SqliteOptions.js.map +1 -1
  9. package/lib/module/db/OPSQLiteConnection.js +3 -0
  10. package/lib/module/db/OPSQLiteConnection.js.map +1 -1
  11. package/lib/module/db/OPSqliteAdapter.js +14 -4
  12. package/lib/module/db/OPSqliteAdapter.js.map +1 -1
  13. package/lib/module/db/SqliteOptions.js +8 -0
  14. package/lib/module/db/SqliteOptions.js.map +1 -1
  15. package/lib/typescript/commonjs/src/db/OPSQLiteConnection.d.ts +1 -0
  16. package/lib/typescript/commonjs/src/db/OPSQLiteConnection.d.ts.map +1 -1
  17. package/lib/typescript/commonjs/src/db/OPSqliteAdapter.d.ts +1 -0
  18. package/lib/typescript/commonjs/src/db/OPSqliteAdapter.d.ts.map +1 -1
  19. package/lib/typescript/commonjs/src/db/SqliteOptions.d.ts +17 -0
  20. package/lib/typescript/commonjs/src/db/SqliteOptions.d.ts.map +1 -1
  21. package/lib/typescript/commonjs/tsconfig.build.tsbuildinfo +1 -1
  22. package/lib/typescript/module/src/db/OPSQLiteConnection.d.ts +1 -0
  23. package/lib/typescript/module/src/db/OPSQLiteConnection.d.ts.map +1 -1
  24. package/lib/typescript/module/src/db/OPSqliteAdapter.d.ts +1 -0
  25. package/lib/typescript/module/src/db/OPSqliteAdapter.d.ts.map +1 -1
  26. package/lib/typescript/module/src/db/SqliteOptions.d.ts +17 -0
  27. package/lib/typescript/module/src/db/SqliteOptions.d.ts.map +1 -1
  28. package/lib/typescript/module/tsconfig.build.tsbuildinfo +1 -1
  29. package/package.json +4 -5
  30. package/powersync-op-sqlite.podspec +1 -1
  31. package/src/db/OPSQLiteConnection.ts +4 -0
  32. package/src/db/OPSqliteAdapter.ts +20 -4
  33. package/src/db/SqliteOptions.ts +22 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/op-sqlite",
3
- "version": "0.0.0-dev-20250207081035",
3
+ "version": "0.0.0-dev-20250319141441",
4
4
  "description": "PowerSync - sync Postgres or MongoDB with SQLite in your React Native app for offline-first and real-time data",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/commonjs/index.js",
@@ -59,13 +59,13 @@
59
59
  },
60
60
  "peerDependencies": {
61
61
  "@op-engineering/op-sqlite": "^11.2.13",
62
- "@powersync/common": "0.0.0-dev-20250207081035",
62
+ "@powersync/common": "0.0.0-dev-20250319141441",
63
63
  "react": "*",
64
64
  "react-native": "*"
65
65
  },
66
66
  "dependencies": {
67
67
  "async-lock": "^1.4.0",
68
- "@powersync/common": "0.0.0-dev-20250207081035"
68
+ "@powersync/common": "0.0.0-dev-20250319141441"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@op-engineering/op-sqlite": "^11.2.13",
@@ -80,8 +80,7 @@
80
80
  "react": "18.3.1",
81
81
  "react-native": "0.75.3",
82
82
  "react-native-builder-bob": "^0.30.2",
83
- "turbo": "^1.10.7",
84
- "typescript": "^5.2.2"
83
+ "turbo": "^1.10.7"
85
84
  },
86
85
  "eslintIgnore": [
87
86
  "node_modules/",
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
17
17
 
18
18
  s.dependency "React-callinvoker"
19
19
  s.dependency "React"
20
- s.dependency "powersync-sqlite-core", "~> 0.3.8"
20
+ s.dependency "powersync-sqlite-core", "~> 0.3.12"
21
21
  if defined?(install_modules_dependencies())
22
22
  install_modules_dependencies(s)
23
23
  else
@@ -97,6 +97,10 @@ export class OPSQLiteConnection extends BaseObserver<DBAdapterListener> {
97
97
  };
98
98
  }
99
99
 
100
+ async executeRaw(query: string, params?: any[]): Promise<any[][]> {
101
+ return await this.DB.executeRaw(query, params);
102
+ }
103
+
100
104
  async executeBatch(query: string, params: any[][] = []): Promise<QueryResult> {
101
105
  const tuple: SQLBatchTuple[] = [[query, params[0]]];
102
106
  params.slice(1).forEach((p) => tuple.push([query, p]));
@@ -44,19 +44,28 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
44
44
  }
45
45
 
46
46
  protected async init() {
47
- const { lockTimeoutMs, journalMode, journalSizeLimit, synchronous } = this.options.sqliteOptions!;
47
+ const { lockTimeoutMs, journalMode, journalSizeLimit, synchronous, cacheSizeKb, temporaryStorage } =
48
+ this.options.sqliteOptions!;
48
49
  const dbFilename = this.options.name;
49
50
 
50
51
  this.writeConnection = await this.openConnection(dbFilename);
51
52
 
52
- const statements: string[] = [
53
+ const baseStatements = [
53
54
  `PRAGMA busy_timeout = ${lockTimeoutMs}`,
55
+ `PRAGMA cache_size = -${cacheSizeKb}`,
56
+ `PRAGMA temp_store = ${temporaryStorage}`
57
+ ];
58
+
59
+ const writeConnectionStatements = [
60
+ ...baseStatements,
54
61
  `PRAGMA journal_mode = ${journalMode}`,
55
62
  `PRAGMA journal_size_limit = ${journalSizeLimit}`,
56
63
  `PRAGMA synchronous = ${synchronous}`
57
64
  ];
58
65
 
59
- for (const statement of statements) {
66
+ const readConnectionStatements = [...baseStatements, 'PRAGMA query_only = true'];
67
+
68
+ for (const statement of writeConnectionStatements) {
60
69
  for (let tries = 0; tries < 30; tries++) {
61
70
  try {
62
71
  await this.writeConnection!.execute(statement);
@@ -79,7 +88,9 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
79
88
  this.readConnections = [];
80
89
  for (let i = 0; i < READ_CONNECTIONS; i++) {
81
90
  const conn = await this.openConnection(dbFilename);
82
- await conn.execute('PRAGMA query_only = true');
91
+ for (let statement of readConnectionStatements) {
92
+ await conn.execute(statement);
93
+ }
83
94
  this.readConnections.push({ busy: false, connection: conn });
84
95
  }
85
96
  }
@@ -234,6 +245,10 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
234
245
  return this.writeLock((ctx) => ctx.execute(query, params));
235
246
  }
236
247
 
248
+ executeRaw(query: string, params?: any[]) {
249
+ return this.writeLock((ctx) => ctx.executeRaw(query, params));
250
+ }
251
+
237
252
  async executeBatch(query: string, params: any[][] = []): Promise<QueryResult> {
238
253
  return this.writeLock((ctx) => ctx.executeBatch(query, params));
239
254
  }
@@ -261,6 +276,7 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
261
276
  await connection.execute('BEGIN');
262
277
  const result = await fn({
263
278
  execute: (query, params) => connection.execute(query, params),
279
+ executeRaw: (query, params) => connection.executeRaw(query, params),
264
280
  get: (query, params) => connection.get(query, params),
265
281
  getAll: (query, params) => connection.getAll(query, params),
266
282
  getOptional: (query, params) => connection.getOptional(query, params),
@@ -30,6 +30,21 @@ export interface SqliteOptions {
30
30
  */
31
31
  encryptionKey?: string | null;
32
32
 
33
+ /**
34
+ * Where to store SQLite temporary files. Defaults to 'MEMORY'.
35
+ * Setting this to `FILESYSTEM` can cause issues with larger queries or datasets.
36
+ *
37
+ * For details, see: https://www.sqlite.org/pragma.html#pragma_temp_store
38
+ */
39
+ temporaryStorage?: TemporaryStorageOption;
40
+
41
+ /**
42
+ * Maximum SQLite cache size. Defaults to 50MB.
43
+ *
44
+ * For details, see: https://www.sqlite.org/pragma.html#pragma_cache_size
45
+ */
46
+ cacheSizeKb?: number;
47
+
33
48
  /**
34
49
  * Load extensions using the path and entryPoint.
35
50
  * More info can be found here https://op-engineering.github.io/op-sqlite/docs/api#loading-extensions.
@@ -40,6 +55,11 @@ export interface SqliteOptions {
40
55
  }>;
41
56
  }
42
57
 
58
+ export enum TemporaryStorageOption {
59
+ MEMORY = 'memory',
60
+ FILESYSTEM = 'file'
61
+ }
62
+
43
63
  // SQLite journal mode. Set on the primary connection.
44
64
  // This library is written with WAL mode in mind - other modes may cause
45
65
  // unexpected locking behavior.
@@ -65,6 +85,8 @@ export const DEFAULT_SQLITE_OPTIONS: Required<SqliteOptions> = {
65
85
  journalMode: SqliteJournalMode.wal,
66
86
  synchronous: SqliteSynchronous.normal,
67
87
  journalSizeLimit: 6 * 1024 * 1024,
88
+ cacheSizeKb: 50 * 1024,
89
+ temporaryStorage: TemporaryStorageOption.MEMORY,
68
90
  lockTimeoutMs: 30000,
69
91
  encryptionKey: null,
70
92
  extensions: []