@powersync/op-sqlite 0.3.0 → 0.4.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/README.md +4 -8
- package/lib/commonjs/db/OPSqliteAdapter.js +16 -5
- package/lib/commonjs/db/OPSqliteAdapter.js.map +1 -1
- package/lib/commonjs/db/SqliteOptions.js +8 -2
- package/lib/commonjs/db/SqliteOptions.js.map +1 -1
- package/lib/module/db/OPSqliteAdapter.js +16 -5
- package/lib/module/db/OPSqliteAdapter.js.map +1 -1
- package/lib/module/db/SqliteOptions.js +8 -0
- package/lib/module/db/SqliteOptions.js.map +1 -1
- package/lib/typescript/commonjs/src/db/OPSqliteAdapter.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/db/SqliteOptions.d.ts +17 -0
- package/lib/typescript/commonjs/src/db/SqliteOptions.d.ts.map +1 -1
- package/lib/typescript/commonjs/tsconfig.build.tsbuildinfo +1 -1
- package/lib/typescript/module/src/db/OPSqliteAdapter.d.ts.map +1 -1
- package/lib/typescript/module/src/db/SqliteOptions.d.ts +17 -0
- package/lib/typescript/module/src/db/SqliteOptions.d.ts.map +1 -1
- package/lib/typescript/module/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/db/OPSqliteAdapter.ts +24 -21
- 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.
|
|
3
|
+
"version": "0.4.0",
|
|
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": "^1.
|
|
62
|
+
"@powersync/common": "^1.24.0",
|
|
63
63
|
"react": "*",
|
|
64
64
|
"react-native": "*"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"async-lock": "^1.4.0",
|
|
68
|
-
"@powersync/common": "1.
|
|
68
|
+
"@powersync/common": "1.24.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@op-engineering/op-sqlite": "^11.2.13",
|
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
DBAdapter,
|
|
4
|
-
DBAdapterListener,
|
|
5
|
-
DBLockOptions,
|
|
6
|
-
QueryResult,
|
|
7
|
-
Transaction
|
|
8
|
-
} from '@powersync/common';
|
|
9
|
-
import {
|
|
10
|
-
ANDROID_DATABASE_PATH,
|
|
11
|
-
getDylibPath,
|
|
12
|
-
IOS_LIBRARY_PATH,
|
|
13
|
-
open,
|
|
14
|
-
type DB
|
|
15
|
-
} from '@op-engineering/op-sqlite';
|
|
1
|
+
import { BaseObserver, DBAdapter, DBAdapterListener, DBLockOptions, QueryResult, Transaction } from '@powersync/common';
|
|
2
|
+
import { ANDROID_DATABASE_PATH, getDylibPath, IOS_LIBRARY_PATH, open, type DB } from '@op-engineering/op-sqlite';
|
|
16
3
|
import Lock from 'async-lock';
|
|
17
4
|
import { OPSQLiteConnection } from './OPSQLiteConnection';
|
|
18
5
|
import { Platform } from 'react-native';
|
|
@@ -57,19 +44,28 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
57
44
|
}
|
|
58
45
|
|
|
59
46
|
protected async init() {
|
|
60
|
-
const { lockTimeoutMs, journalMode, journalSizeLimit, synchronous } =
|
|
47
|
+
const { lockTimeoutMs, journalMode, journalSizeLimit, synchronous, cacheSizeKb, temporaryStorage } =
|
|
48
|
+
this.options.sqliteOptions!;
|
|
61
49
|
const dbFilename = this.options.name;
|
|
62
50
|
|
|
63
51
|
this.writeConnection = await this.openConnection(dbFilename);
|
|
64
52
|
|
|
65
|
-
const
|
|
53
|
+
const baseStatements = [
|
|
66
54
|
`PRAGMA busy_timeout = ${lockTimeoutMs}`,
|
|
55
|
+
`PRAGMA cache_size = -${cacheSizeKb}`,
|
|
56
|
+
`PRAGMA temp_store = ${temporaryStorage}`
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
const writeConnectionStatements = [
|
|
60
|
+
...baseStatements,
|
|
67
61
|
`PRAGMA journal_mode = ${journalMode}`,
|
|
68
62
|
`PRAGMA journal_size_limit = ${journalSizeLimit}`,
|
|
69
63
|
`PRAGMA synchronous = ${synchronous}`
|
|
70
64
|
];
|
|
71
65
|
|
|
72
|
-
|
|
66
|
+
const readConnectionStatements = [...baseStatements, 'PRAGMA query_only = true'];
|
|
67
|
+
|
|
68
|
+
for (const statement of writeConnectionStatements) {
|
|
73
69
|
for (let tries = 0; tries < 30; tries++) {
|
|
74
70
|
try {
|
|
75
71
|
await this.writeConnection!.execute(statement);
|
|
@@ -92,7 +88,9 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
92
88
|
this.readConnections = [];
|
|
93
89
|
for (let i = 0; i < READ_CONNECTIONS; i++) {
|
|
94
90
|
const conn = await this.openConnection(dbFilename);
|
|
95
|
-
|
|
91
|
+
for (let statement of readConnectionStatements) {
|
|
92
|
+
await conn.execute(statement);
|
|
93
|
+
}
|
|
96
94
|
this.readConnections.push({ busy: false, connection: conn });
|
|
97
95
|
}
|
|
98
96
|
}
|
|
@@ -283,7 +281,12 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
283
281
|
await commit();
|
|
284
282
|
return result;
|
|
285
283
|
} catch (ex) {
|
|
286
|
-
|
|
284
|
+
try {
|
|
285
|
+
await rollback();
|
|
286
|
+
} catch (ex2) {
|
|
287
|
+
// In rare cases, a rollback may fail.
|
|
288
|
+
// Safe to ignore.
|
|
289
|
+
}
|
|
287
290
|
throw ex;
|
|
288
291
|
}
|
|
289
292
|
}
|
|
@@ -292,7 +295,7 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
292
295
|
await this.initialized;
|
|
293
296
|
await this.writeConnection!.refreshSchema();
|
|
294
297
|
|
|
295
|
-
if(this.readConnections) {
|
|
298
|
+
if (this.readConnections) {
|
|
296
299
|
for (let readConnection of this.readConnections) {
|
|
297
300
|
await readConnection.connection.refreshSchema();
|
|
298
301
|
}
|
package/src/db/SqliteOptions.ts
CHANGED
|
@@ -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: []
|