@powersync/op-sqlite 0.2.1 → 0.3.1
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 +36 -0
- package/android/src/main/java/com/powersync/opsqlite/PowerSyncOpSqlitePackage.kt +4 -8
- package/ios/PowerSyncOpSqlite.mm +0 -5
- package/lib/commonjs/db/OPSqliteAdapter.js +24 -11
- package/lib/commonjs/db/OPSqliteAdapter.js.map +1 -1
- package/lib/commonjs/db/SqliteOptions.js +2 -1
- package/lib/commonjs/db/SqliteOptions.js.map +1 -1
- package/lib/commonjs/index.js +0 -16
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/db/OPSqliteAdapter.js +26 -13
- package/lib/module/db/OPSqliteAdapter.js.map +1 -1
- package/lib/module/db/SqliteOptions.js +2 -1
- package/lib/module/db/SqliteOptions.js.map +1 -1
- package/lib/module/index.js +0 -15
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/commonjs/src/db/OPSqliteAdapter.d.ts +2 -1
- package/lib/typescript/commonjs/src/db/OPSqliteAdapter.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/db/SqliteOptions.d.ts +9 -1
- package/lib/typescript/commonjs/src/db/SqliteOptions.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +0 -1
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/tsconfig.build.tsbuildinfo +1 -1
- package/lib/typescript/module/src/db/OPSqliteAdapter.d.ts +2 -1
- package/lib/typescript/module/src/db/OPSqliteAdapter.d.ts.map +1 -1
- package/lib/typescript/module/src/db/SqliteOptions.d.ts +9 -1
- package/lib/typescript/module/src/db/SqliteOptions.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +0 -1
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/db/OPSqliteAdapter.ts +27 -12
- package/src/db/SqliteOptions.ts +12 -2
- package/src/index.ts +4 -30
- package/android/src/main/java/com/powersync/opsqlite/PowerSyncOpSqliteModule.kt +0 -25
- package/android/src/newarch/PowerSyncOpSqliteSpec.kt +0 -7
- package/android/src/oldarch/PowerSyncOpSqliteSpec.kt +0 -11
- package/lib/commonjs/NativePowerSyncOpSqlite.js +0 -9
- package/lib/commonjs/NativePowerSyncOpSqlite.js.map +0 -1
- package/lib/module/NativePowerSyncOpSqlite.js +0 -5
- package/lib/module/NativePowerSyncOpSqlite.js.map +0 -1
- package/lib/typescript/commonjs/src/NativePowerSyncOpSqlite.d.ts +0 -7
- package/lib/typescript/commonjs/src/NativePowerSyncOpSqlite.d.ts.map +0 -1
- package/lib/typescript/module/src/NativePowerSyncOpSqlite.d.ts +0 -7
- package/lib/typescript/module/src/NativePowerSyncOpSqlite.d.ts.map +0 -1
- package/src/NativePowerSyncOpSqlite.ts +0 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/op-sqlite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
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.23.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.23.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@op-engineering/op-sqlite": "^11.2.13",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BaseObserver, DBAdapter, DBAdapterListener, DBLockOptions, QueryResult, Transaction } from '@powersync/common';
|
|
2
|
-
import { ANDROID_DATABASE_PATH, IOS_LIBRARY_PATH, open, type DB } from '@op-engineering/op-sqlite';
|
|
2
|
+
import { ANDROID_DATABASE_PATH, getDylibPath, IOS_LIBRARY_PATH, open, type DB } from '@op-engineering/op-sqlite';
|
|
3
3
|
import Lock from 'async-lock';
|
|
4
4
|
import { OPSQLiteConnection } from './OPSQLiteConnection';
|
|
5
|
-
import {
|
|
5
|
+
import { Platform } from 'react-native';
|
|
6
6
|
import { SqliteOptions } from './SqliteOptions';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -44,7 +44,7 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
protected async init() {
|
|
47
|
-
const { lockTimeoutMs, journalMode, journalSizeLimit, synchronous
|
|
47
|
+
const { lockTimeoutMs, journalMode, journalSizeLimit, synchronous } = this.options.sqliteOptions!;
|
|
48
48
|
const dbFilename = this.options.name;
|
|
49
49
|
|
|
50
50
|
this.writeConnection = await this.openConnection(dbFilename);
|
|
@@ -86,10 +86,11 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
86
86
|
|
|
87
87
|
protected async openConnection(filenameOverride?: string): Promise<OPSQLiteConnection> {
|
|
88
88
|
const dbFilename = filenameOverride ?? this.options.name;
|
|
89
|
-
const DB: DB = this.openDatabase(dbFilename, this.options.sqliteOptions
|
|
89
|
+
const DB: DB = this.openDatabase(dbFilename, this.options.sqliteOptions?.encryptionKey ?? undefined);
|
|
90
90
|
|
|
91
|
-
//Load
|
|
92
|
-
this.
|
|
91
|
+
//Load extensions for all connections
|
|
92
|
+
this.loadAdditionalExtensions(DB);
|
|
93
|
+
this.loadPowerSyncExtension(DB);
|
|
93
94
|
|
|
94
95
|
await DB.execute('SELECT powersync_init()');
|
|
95
96
|
|
|
@@ -124,10 +125,17 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
124
125
|
}
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
private
|
|
128
|
+
private loadAdditionalExtensions(DB: DB) {
|
|
129
|
+
if (this.options.sqliteOptions?.extensions && this.options.sqliteOptions.extensions.length > 0) {
|
|
130
|
+
for (const extension of this.options.sqliteOptions.extensions) {
|
|
131
|
+
DB.loadExtension(extension.path, extension.entryPoint);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private async loadPowerSyncExtension(DB: DB) {
|
|
128
137
|
if (Platform.OS === 'ios') {
|
|
129
|
-
const
|
|
130
|
-
const libPath = `${bundlePath}/Frameworks/powersync-sqlite-core.framework/powersync-sqlite-core`;
|
|
138
|
+
const libPath = getDylibPath('co.powersync.sqlitecore', 'powersync-sqlite-core');
|
|
131
139
|
DB.loadExtension(libPath, 'sqlite3_powersync_init');
|
|
132
140
|
} else {
|
|
133
141
|
DB.loadExtension('libpowersync', 'sqlite3_powersync_init');
|
|
@@ -262,7 +270,12 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
262
270
|
await commit();
|
|
263
271
|
return result;
|
|
264
272
|
} catch (ex) {
|
|
265
|
-
|
|
273
|
+
try {
|
|
274
|
+
await rollback();
|
|
275
|
+
} catch (ex2) {
|
|
276
|
+
// In rare cases, a rollback may fail.
|
|
277
|
+
// Safe to ignore.
|
|
278
|
+
}
|
|
266
279
|
throw ex;
|
|
267
280
|
}
|
|
268
281
|
}
|
|
@@ -271,8 +284,10 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
271
284
|
await this.initialized;
|
|
272
285
|
await this.writeConnection!.refreshSchema();
|
|
273
286
|
|
|
274
|
-
|
|
275
|
-
|
|
287
|
+
if (this.readConnections) {
|
|
288
|
+
for (let readConnection of this.readConnections) {
|
|
289
|
+
await readConnection.connection.refreshSchema();
|
|
290
|
+
}
|
|
276
291
|
}
|
|
277
292
|
}
|
|
278
293
|
}
|
package/src/db/SqliteOptions.ts
CHANGED
|
@@ -28,7 +28,16 @@ export interface SqliteOptions {
|
|
|
28
28
|
* Encryption key for the database.
|
|
29
29
|
* If set, the database will be encrypted using SQLCipher.
|
|
30
30
|
*/
|
|
31
|
-
encryptionKey?: string;
|
|
31
|
+
encryptionKey?: string | null;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Load extensions using the path and entryPoint.
|
|
35
|
+
* More info can be found here https://op-engineering.github.io/op-sqlite/docs/api#loading-extensions.
|
|
36
|
+
*/
|
|
37
|
+
extensions?: Array<{
|
|
38
|
+
path: string;
|
|
39
|
+
entryPoint?: string;
|
|
40
|
+
}>;
|
|
32
41
|
}
|
|
33
42
|
|
|
34
43
|
// SQLite journal mode. Set on the primary connection.
|
|
@@ -57,5 +66,6 @@ export const DEFAULT_SQLITE_OPTIONS: Required<SqliteOptions> = {
|
|
|
57
66
|
synchronous: SqliteSynchronous.normal,
|
|
58
67
|
journalSizeLimit: 6 * 1024 * 1024,
|
|
59
68
|
lockTimeoutMs: 30000,
|
|
60
|
-
encryptionKey: null
|
|
69
|
+
encryptionKey: null,
|
|
70
|
+
extensions: []
|
|
61
71
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,30 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
6
|
-
'- You rebuilt the app after installing the package\n' +
|
|
7
|
-
'- You are not using Expo Go\n';
|
|
8
|
-
|
|
9
|
-
const isTurboModuleEnabled = global.__turboModuleProxy != null;
|
|
10
|
-
|
|
11
|
-
const PowerSyncOpSqliteModule = isTurboModuleEnabled
|
|
12
|
-
? require('./NativePowerSyncOpSqlite').default
|
|
13
|
-
: NativeModules.PowerSyncOpSqlite;
|
|
14
|
-
|
|
15
|
-
const PowerSyncOpSqlite = PowerSyncOpSqliteModule
|
|
16
|
-
? PowerSyncOpSqliteModule
|
|
17
|
-
: new Proxy(
|
|
18
|
-
{},
|
|
19
|
-
{
|
|
20
|
-
get() {
|
|
21
|
-
throw new Error(LINKING_ERROR);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
export function getBundlePath(): string {
|
|
27
|
-
return PowerSyncOpSqlite.getBundlePath();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { OPSqliteOpenFactory, OPSQLiteOpenFactoryOptions } from './db/OPSqliteDBOpenFactory';
|
|
1
|
+
export {
|
|
2
|
+
OPSqliteOpenFactory,
|
|
3
|
+
OPSQLiteOpenFactoryOptions
|
|
4
|
+
} from './db/OPSqliteDBOpenFactory';
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
package com.powersync.opsqlite
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
-
import com.facebook.react.bridge.ReactMethod
|
|
5
|
-
import com.facebook.react.bridge.Promise
|
|
6
|
-
|
|
7
|
-
class PowerSyncOpSqliteModule internal constructor(context: ReactApplicationContext) :
|
|
8
|
-
PowerSyncOpSqliteSpec(context) {
|
|
9
|
-
|
|
10
|
-
@ReactMethod
|
|
11
|
-
override fun getBundlePath(): String {
|
|
12
|
-
//This method should only be used for iOS platforms
|
|
13
|
-
//Ensure you wrap its usage with a (Platform.OS === 'ios') check
|
|
14
|
-
//Returns an empty string for android
|
|
15
|
-
return ""
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
override fun getName(): String {
|
|
19
|
-
return NAME
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
companion object {
|
|
23
|
-
const val NAME = "PowerSyncOpSqlite"
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
package com.powersync.opsqlite
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
5
|
-
import com.facebook.react.bridge.Promise
|
|
6
|
-
|
|
7
|
-
abstract class PowerSyncOpSqliteSpec internal constructor(context: ReactApplicationContext) :
|
|
8
|
-
ReactContextBaseJavaModule(context) {
|
|
9
|
-
|
|
10
|
-
abstract fun getBundlePath(): String
|
|
11
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _reactNative = require("react-native");
|
|
8
|
-
var _default = exports.default = _reactNative.TurboModuleRegistry.getEnforcing('PowerSyncOpSqlite');
|
|
9
|
-
//# sourceMappingURL=NativePowerSyncOpSqlite.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativePowerSyncOpSqlite.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAAmD,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAMpCC,gCAAmB,CAACC,YAAY,CAAO,mBAAmB,CAAC","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativePowerSyncOpSqlite.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;AAMlD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,mBAAmB,CAAC","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NativePowerSyncOpSqlite.d.ts","sourceRoot":"","sources":["../../../../src/NativePowerSyncOpSqlite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,aAAa,IAAI,MAAM,CAAC;CACzB;;AAED,wBAA2E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NativePowerSyncOpSqlite.d.ts","sourceRoot":"","sources":["../../../../src/NativePowerSyncOpSqlite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,aAAa,IAAI,MAAM,CAAC;CACzB;;AAED,wBAA2E"}
|