@powersync/op-sqlite 0.0.0-dev-20251030153614 → 0.0.0-dev-20251106124255
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/lib/commonjs/db/OPSQLiteConnection.js +24 -0
- package/lib/commonjs/db/OPSQLiteConnection.js.map +1 -1
- package/lib/commonjs/db/OPSqliteAdapter.js +7 -5
- package/lib/commonjs/db/OPSqliteAdapter.js.map +1 -1
- package/lib/commonjs/db/OPSqliteDBOpenFactory.js +2 -1
- package/lib/commonjs/db/OPSqliteDBOpenFactory.js.map +1 -1
- package/lib/module/db/OPSQLiteConnection.js +24 -0
- package/lib/module/db/OPSQLiteConnection.js.map +1 -1
- package/lib/module/db/OPSqliteAdapter.js +7 -5
- package/lib/module/db/OPSqliteAdapter.js.map +1 -1
- package/lib/module/db/OPSqliteDBOpenFactory.js +2 -1
- package/lib/module/db/OPSqliteDBOpenFactory.js.map +1 -1
- package/lib/typescript/commonjs/src/db/OPSQLiteConnection.d.ts +2 -0
- package/lib/typescript/commonjs/src/db/OPSQLiteConnection.d.ts.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/OPSqliteDBOpenFactory.d.ts.map +1 -1
- package/lib/typescript/commonjs/tsconfig.build.tsbuildinfo +1 -1
- package/lib/typescript/module/src/db/OPSQLiteConnection.d.ts +2 -0
- package/lib/typescript/module/src/db/OPSQLiteConnection.d.ts.map +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/OPSqliteDBOpenFactory.d.ts.map +1 -1
- package/lib/typescript/module/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/db/OPSQLiteConnection.ts +28 -0
- package/src/db/OPSqliteAdapter.ts +8 -5
- package/src/db/OPSqliteDBOpenFactory.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/op-sqlite",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20251106124255",
|
|
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": "^13.0.0 || ^14.0.0",
|
|
62
|
-
"@powersync/common": "0.0.0-dev-
|
|
62
|
+
"@powersync/common": "0.0.0-dev-20251106124255",
|
|
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-
|
|
68
|
+
"@powersync/common": "0.0.0-dev-20251106124255"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@op-engineering/op-sqlite": "^14.0.2",
|
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
|
|
11
11
|
export type OPSQLiteConnectionOptions = {
|
|
12
12
|
baseDB: DB;
|
|
13
|
+
debugMode: boolean;
|
|
14
|
+
connectionName: string;
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
export type OPSQLiteUpdateNotification = {
|
|
@@ -35,6 +37,16 @@ export class OPSQLiteConnection extends BaseObserver<DBAdapterListener> {
|
|
|
35
37
|
this.DB.updateHook((update) => {
|
|
36
38
|
this.addTableUpdate(update);
|
|
37
39
|
});
|
|
40
|
+
|
|
41
|
+
if (options.debugMode) {
|
|
42
|
+
const c = this.options.connectionName;
|
|
43
|
+
this.execute = withDebug(this.execute.bind(this), `[SQL execute ${c}]`);
|
|
44
|
+
this.executeRaw = withDebug(this.executeRaw.bind(this), `[SQL executeRaw ${c}]`);
|
|
45
|
+
this.executeBatch = withDebug(this.executeBatch.bind(this), `[SQL executeBatch ${c}]`);
|
|
46
|
+
this.get = withDebug(this.get.bind(this), `[SQL get ${c}]`);
|
|
47
|
+
this.getAll = withDebug(this.getAll.bind(this), `[SQL getAll ${c}]`);
|
|
48
|
+
this.getOptional = withDebug(this.getOptional.bind(this), `[SQL getOptional ${c}]`);
|
|
49
|
+
}
|
|
38
50
|
}
|
|
39
51
|
|
|
40
52
|
addTableUpdate(update: OPSQLiteUpdateNotification) {
|
|
@@ -133,3 +145,19 @@ export class OPSQLiteConnection extends BaseObserver<DBAdapterListener> {
|
|
|
133
145
|
await this.get("PRAGMA table_info('sqlite_master')");
|
|
134
146
|
}
|
|
135
147
|
}
|
|
148
|
+
|
|
149
|
+
function withDebug<T extends (sql: string, ...args: any[]) => Promise<any>>(fn: T, name: string): T {
|
|
150
|
+
return (async (sql: string, ...args: any[]): Promise<any> => {
|
|
151
|
+
const start = performance.now();
|
|
152
|
+
try {
|
|
153
|
+
const r = await fn(sql, ...args);
|
|
154
|
+
const duration = performance.now() - start;
|
|
155
|
+
console.log(name, `[${duration.toFixed(1)}ms]`, sql);
|
|
156
|
+
return r;
|
|
157
|
+
} catch (e: any) {
|
|
158
|
+
const duration = performance.now() - start;
|
|
159
|
+
console.error(name, `[ERROR: ${e.message}]`, `[${duration.toFixed(1)}ms]`, sql);
|
|
160
|
+
throw e;
|
|
161
|
+
}
|
|
162
|
+
}) as T;
|
|
163
|
+
}
|
|
@@ -12,6 +12,7 @@ export type OPSQLiteAdapterOptions = {
|
|
|
12
12
|
name: string;
|
|
13
13
|
dbLocation?: string;
|
|
14
14
|
sqliteOptions?: SqliteOptions;
|
|
15
|
+
debugMode?: boolean;
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
enum LockType {
|
|
@@ -50,7 +51,7 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
50
51
|
this.options.sqliteOptions!;
|
|
51
52
|
const dbFilename = this.options.name;
|
|
52
53
|
|
|
53
|
-
this.writeConnection = await this.openConnection(
|
|
54
|
+
this.writeConnection = await this.openConnection('w');
|
|
54
55
|
|
|
55
56
|
const baseStatements = [
|
|
56
57
|
`PRAGMA busy_timeout = ${lockTimeoutMs}`,
|
|
@@ -89,7 +90,7 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
89
90
|
|
|
90
91
|
this.readConnections = [];
|
|
91
92
|
for (let i = 0; i < READ_CONNECTIONS; i++) {
|
|
92
|
-
const conn = await this.openConnection(
|
|
93
|
+
const conn = await this.openConnection(`r-${i}`);
|
|
93
94
|
for (let statement of readConnectionStatements) {
|
|
94
95
|
await conn.execute(statement);
|
|
95
96
|
}
|
|
@@ -97,8 +98,8 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
protected async openConnection(
|
|
101
|
-
const dbFilename =
|
|
101
|
+
protected async openConnection(connectionName: string): Promise<OPSQLiteConnection> {
|
|
102
|
+
const dbFilename = this.options.name;
|
|
102
103
|
const DB: DB = this.openDatabase(dbFilename, this.options.sqliteOptions?.encryptionKey ?? undefined);
|
|
103
104
|
|
|
104
105
|
//Load extensions for all connections
|
|
@@ -108,7 +109,9 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
108
109
|
await DB.execute('SELECT powersync_init()');
|
|
109
110
|
|
|
110
111
|
return new OPSQLiteConnection({
|
|
111
|
-
baseDB: DB
|
|
112
|
+
baseDB: DB,
|
|
113
|
+
debugMode: this.options.debugMode ?? false,
|
|
114
|
+
connectionName
|
|
112
115
|
});
|
|
113
116
|
}
|
|
114
117
|
|
|
@@ -19,7 +19,8 @@ export class OPSqliteOpenFactory implements SQLOpenFactory {
|
|
|
19
19
|
return new OPSQLiteDBAdapter({
|
|
20
20
|
name: this.options.dbFilename,
|
|
21
21
|
dbLocation: this.options.dbLocation,
|
|
22
|
-
sqliteOptions: this.sqliteOptions
|
|
22
|
+
sqliteOptions: this.sqliteOptions,
|
|
23
|
+
debugMode: this.options.debugMode
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
}
|