@powersync/op-sqlite 0.2.0 → 0.3.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 +36 -0
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/powersync/opsqlite/PowerSyncOpSqlitePackage.kt +4 -8
- package/ios/PowerSyncOpSqlite.mm +0 -5
- package/lib/commonjs/db/OPSqliteAdapter.js +19 -13
- 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 +21 -15
- 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 +6 -6
- package/powersync-op-sqlite.podspec +1 -1
- package/src/db/OPSqliteAdapter.ts +36 -15
- 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.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",
|
|
@@ -58,17 +58,17 @@
|
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"@op-engineering/op-sqlite": "^
|
|
62
|
-
"@powersync/common": "^1.22.
|
|
61
|
+
"@op-engineering/op-sqlite": "^11.2.13",
|
|
62
|
+
"@powersync/common": "^1.22.2",
|
|
63
63
|
"react": "*",
|
|
64
64
|
"react-native": "*"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"async-lock": "^1.4.0",
|
|
68
|
-
"@powersync/common": "1.22.
|
|
68
|
+
"@powersync/common": "1.22.2"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@op-engineering/op-sqlite": "^
|
|
71
|
+
"@op-engineering/op-sqlite": "^11.2.13",
|
|
72
72
|
"@react-native/eslint-config": "^0.73.1",
|
|
73
73
|
"@types/async-lock": "^1.4.0",
|
|
74
74
|
"@types/react": "^18.2.44",
|
|
@@ -131,6 +131,6 @@
|
|
|
131
131
|
"build:prod": "bob build",
|
|
132
132
|
"typecheck": "tsc",
|
|
133
133
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
134
|
-
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib"
|
|
134
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib node_modules"
|
|
135
135
|
}
|
|
136
136
|
}
|
|
@@ -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.
|
|
20
|
+
s.dependency "powersync-sqlite-core", "~> 0.3.8"
|
|
21
21
|
if defined?(install_modules_dependencies())
|
|
22
22
|
install_modules_dependencies(s)
|
|
23
23
|
else
|
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
BaseObserver,
|
|
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';
|
|
3
16
|
import Lock from 'async-lock';
|
|
4
17
|
import { OPSQLiteConnection } from './OPSQLiteConnection';
|
|
5
|
-
import {
|
|
18
|
+
import { Platform } from 'react-native';
|
|
6
19
|
import { SqliteOptions } from './SqliteOptions';
|
|
7
20
|
|
|
8
21
|
/**
|
|
@@ -44,7 +57,7 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
44
57
|
}
|
|
45
58
|
|
|
46
59
|
protected async init() {
|
|
47
|
-
const { lockTimeoutMs, journalMode, journalSizeLimit, synchronous
|
|
60
|
+
const { lockTimeoutMs, journalMode, journalSizeLimit, synchronous } = this.options.sqliteOptions!;
|
|
48
61
|
const dbFilename = this.options.name;
|
|
49
62
|
|
|
50
63
|
this.writeConnection = await this.openConnection(dbFilename);
|
|
@@ -78,9 +91,7 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
78
91
|
|
|
79
92
|
this.readConnections = [];
|
|
80
93
|
for (let i = 0; i < READ_CONNECTIONS; i++) {
|
|
81
|
-
|
|
82
|
-
let dbName = './'.repeat(i + 1) + dbFilename;
|
|
83
|
-
const conn = await this.openConnection(dbName);
|
|
94
|
+
const conn = await this.openConnection(dbFilename);
|
|
84
95
|
await conn.execute('PRAGMA query_only = true');
|
|
85
96
|
this.readConnections.push({ busy: false, connection: conn });
|
|
86
97
|
}
|
|
@@ -88,10 +99,11 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
88
99
|
|
|
89
100
|
protected async openConnection(filenameOverride?: string): Promise<OPSQLiteConnection> {
|
|
90
101
|
const dbFilename = filenameOverride ?? this.options.name;
|
|
91
|
-
const DB: DB = this.openDatabase(dbFilename, this.options.sqliteOptions
|
|
102
|
+
const DB: DB = this.openDatabase(dbFilename, this.options.sqliteOptions?.encryptionKey ?? undefined);
|
|
92
103
|
|
|
93
|
-
//Load
|
|
94
|
-
this.
|
|
104
|
+
//Load extensions for all connections
|
|
105
|
+
this.loadAdditionalExtensions(DB);
|
|
106
|
+
this.loadPowerSyncExtension(DB);
|
|
95
107
|
|
|
96
108
|
await DB.execute('SELECT powersync_init()');
|
|
97
109
|
|
|
@@ -126,10 +138,17 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
126
138
|
}
|
|
127
139
|
}
|
|
128
140
|
|
|
129
|
-
private
|
|
141
|
+
private loadAdditionalExtensions(DB: DB) {
|
|
142
|
+
if (this.options.sqliteOptions?.extensions && this.options.sqliteOptions.extensions.length > 0) {
|
|
143
|
+
for (const extension of this.options.sqliteOptions.extensions) {
|
|
144
|
+
DB.loadExtension(extension.path, extension.entryPoint);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private async loadPowerSyncExtension(DB: DB) {
|
|
130
150
|
if (Platform.OS === 'ios') {
|
|
131
|
-
const
|
|
132
|
-
const libPath = `${bundlePath}/Frameworks/powersync-sqlite-core.framework/powersync-sqlite-core`;
|
|
151
|
+
const libPath = getDylibPath('co.powersync.sqlitecore', 'powersync-sqlite-core');
|
|
133
152
|
DB.loadExtension(libPath, 'sqlite3_powersync_init');
|
|
134
153
|
} else {
|
|
135
154
|
DB.loadExtension('libpowersync', 'sqlite3_powersync_init');
|
|
@@ -273,8 +292,10 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
273
292
|
await this.initialized;
|
|
274
293
|
await this.writeConnection!.refreshSchema();
|
|
275
294
|
|
|
276
|
-
|
|
277
|
-
|
|
295
|
+
if(this.readConnections) {
|
|
296
|
+
for (let readConnection of this.readConnections) {
|
|
297
|
+
await readConnection.connection.refreshSchema();
|
|
298
|
+
}
|
|
278
299
|
}
|
|
279
300
|
}
|
|
280
301
|
}
|
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"}
|