@powersync/op-sqlite 0.0.0-dev-20260128170935 → 0.0.0-dev-20260202160933
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/package.json +4 -5
- package/powersync-op-sqlite.podspec +1 -0
- package/src/db/OPSqliteAdapter.ts +33 -34
- package/lib/commonjs/db/OPSQLiteConnection.js +0 -106
- package/lib/commonjs/db/OPSQLiteConnection.js.map +0 -1
- package/lib/commonjs/db/OPSqliteAdapter.js +0 -271
- package/lib/commonjs/db/OPSqliteAdapter.js.map +0 -1
- package/lib/commonjs/db/OPSqliteDBOpenFactory.js +0 -26
- package/lib/commonjs/db/OPSqliteDBOpenFactory.js.map +0 -1
- package/lib/commonjs/db/SqliteOptions.js +0 -41
- package/lib/commonjs/db/SqliteOptions.js.map +0 -1
- package/lib/commonjs/index.js +0 -19
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/package.json +0 -1
- package/lib/module/db/OPSQLiteConnection.js +0 -101
- package/lib/module/db/OPSQLiteConnection.js.map +0 -1
- package/lib/module/db/OPSqliteAdapter.js +0 -266
- package/lib/module/db/OPSqliteAdapter.js.map +0 -1
- package/lib/module/db/OPSqliteDBOpenFactory.js +0 -21
- package/lib/module/db/OPSqliteDBOpenFactory.js.map +0 -1
- package/lib/module/db/SqliteOptions.js +0 -39
- package/lib/module/db/SqliteOptions.js.map +0 -1
- package/lib/module/index.js +0 -4
- package/lib/module/index.js.map +0 -1
- package/lib/module/package.json +0 -1
- package/lib/typescript/commonjs/package.json +0 -1
- package/lib/typescript/commonjs/src/db/OPSQLiteConnection.d.ts +0 -28
- package/lib/typescript/commonjs/src/db/OPSQLiteConnection.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/db/OPSqliteAdapter.d.ts +0 -46
- package/lib/typescript/commonjs/src/db/OPSqliteAdapter.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/db/OPSqliteDBOpenFactory.d.ts +0 -12
- package/lib/typescript/commonjs/src/db/OPSqliteDBOpenFactory.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/db/SqliteOptions.d.ts +0 -69
- package/lib/typescript/commonjs/src/db/SqliteOptions.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/index.d.ts +0 -2
- package/lib/typescript/commonjs/src/index.d.ts.map +0 -1
- package/lib/typescript/module/package.json +0 -1
- package/lib/typescript/module/src/db/OPSQLiteConnection.d.ts +0 -28
- package/lib/typescript/module/src/db/OPSQLiteConnection.d.ts.map +0 -1
- package/lib/typescript/module/src/db/OPSqliteAdapter.d.ts +0 -46
- package/lib/typescript/module/src/db/OPSqliteAdapter.d.ts.map +0 -1
- package/lib/typescript/module/src/db/OPSqliteDBOpenFactory.d.ts +0 -12
- package/lib/typescript/module/src/db/OPSqliteDBOpenFactory.d.ts.map +0 -1
- package/lib/typescript/module/src/db/SqliteOptions.d.ts +0 -69
- package/lib/typescript/module/src/db/SqliteOptions.d.ts.map +0 -1
- package/lib/typescript/module/src/index.d.ts +0 -2
- package/lib/typescript/module/src/index.d.ts.map +0 -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-20260202160933",
|
|
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,18 +59,17 @@
|
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@op-engineering/op-sqlite": "^13.0.0 || ^14.0.0 || ^15.0.0",
|
|
62
|
-
"@powersync/common": "0.0.0-dev-
|
|
62
|
+
"@powersync/common": "0.0.0-dev-20260202160933",
|
|
63
63
|
"react": "*",
|
|
64
64
|
"react-native": "*"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"async-
|
|
68
|
-
"@powersync/common": "0.0.0-dev-
|
|
67
|
+
"async-mutex": "^0.5.0",
|
|
68
|
+
"@powersync/common": "0.0.0-dev-20260202160933"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@op-engineering/op-sqlite": "^15.2.2",
|
|
72
72
|
"@react-native/eslint-config": "^0.83.1",
|
|
73
|
-
"@types/async-lock": "^1.4.0",
|
|
74
73
|
"@types/react": "^19.1.1",
|
|
75
74
|
"del-cli": "^7.0.0",
|
|
76
75
|
"eslint": "^8.57.1",
|
|
@@ -4,6 +4,7 @@ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
|
4
4
|
|
|
5
5
|
Pod::Spec.new do |s|
|
|
6
6
|
s.name = "powersync-op-sqlite"
|
|
7
|
+
# Our development versions are not recognized by Cocoapods
|
|
7
8
|
version = package['version']
|
|
8
9
|
if version.include?('-dev')
|
|
9
10
|
s.version = '0.0.0'
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { getDylibPath, open, type DB } from '@op-engineering/op-sqlite';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
BaseObserver,
|
|
4
|
+
DBAdapter,
|
|
5
|
+
DBAdapterListener,
|
|
6
|
+
DBLockOptions,
|
|
7
|
+
QueryResult,
|
|
8
|
+
Transaction,
|
|
9
|
+
mutexRunExclusive
|
|
10
|
+
} from '@powersync/common';
|
|
11
|
+
import { Mutex } from 'async-mutex';
|
|
4
12
|
import { Platform } from 'react-native';
|
|
5
13
|
import { OPSQLiteConnection } from './OPSQLiteConnection';
|
|
6
14
|
import { SqliteOptions } from './SqliteOptions';
|
|
@@ -14,16 +22,11 @@ export type OPSQLiteAdapterOptions = {
|
|
|
14
22
|
sqliteOptions?: SqliteOptions;
|
|
15
23
|
};
|
|
16
24
|
|
|
17
|
-
enum LockType {
|
|
18
|
-
READ = 'read',
|
|
19
|
-
WRITE = 'write'
|
|
20
|
-
}
|
|
21
|
-
|
|
22
25
|
const READ_CONNECTIONS = 5;
|
|
23
26
|
|
|
24
27
|
export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implements DBAdapter {
|
|
25
28
|
name: string;
|
|
26
|
-
protected
|
|
29
|
+
protected writeMutex: Mutex;
|
|
27
30
|
|
|
28
31
|
protected initialized: Promise<void>;
|
|
29
32
|
|
|
@@ -38,7 +41,7 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
38
41
|
super();
|
|
39
42
|
this.name = this.options.name;
|
|
40
43
|
|
|
41
|
-
this.
|
|
44
|
+
this.writeMutex = new Mutex();
|
|
42
45
|
this.readConnections = null;
|
|
43
46
|
this.writeConnection = null;
|
|
44
47
|
this.abortController = new AbortController();
|
|
@@ -198,34 +201,30 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
198
201
|
await this.initialized;
|
|
199
202
|
|
|
200
203
|
return new Promise(async (resolve, reject) => {
|
|
204
|
+
// Set up abort signal listener
|
|
205
|
+
const abortListener = () => {
|
|
206
|
+
reject(new Error('Database connection was closed'));
|
|
207
|
+
};
|
|
208
|
+
this.abortController.signal.addEventListener('abort', abortListener);
|
|
209
|
+
|
|
201
210
|
try {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
resolve(await fn(this.writeConnection!));
|
|
217
|
-
},
|
|
218
|
-
{ timeout: options?.timeoutMs }
|
|
219
|
-
)
|
|
220
|
-
.then(() => {
|
|
221
|
-
// flush updates once a write lock has been released
|
|
222
|
-
this.writeConnection!.flushUpdates();
|
|
223
|
-
})
|
|
224
|
-
.finally(() => {
|
|
225
|
-
this.abortController.signal.removeEventListener('abort', abortListener);
|
|
226
|
-
});
|
|
211
|
+
await mutexRunExclusive(
|
|
212
|
+
this.writeMutex,
|
|
213
|
+
async () => {
|
|
214
|
+
// Check if operation was aborted before executing
|
|
215
|
+
if (this.abortController.signal.aborted) {
|
|
216
|
+
reject(new Error('Database connection was closed'));
|
|
217
|
+
}
|
|
218
|
+
resolve(await fn(this.writeConnection!));
|
|
219
|
+
},
|
|
220
|
+
options
|
|
221
|
+
);
|
|
222
|
+
// flush updates once a write lock has been released
|
|
223
|
+
this.writeConnection!.flushUpdates();
|
|
227
224
|
} catch (ex) {
|
|
228
225
|
reject(ex);
|
|
226
|
+
} finally {
|
|
227
|
+
this.abortController.signal.removeEventListener('abort', abortListener);
|
|
229
228
|
}
|
|
230
229
|
});
|
|
231
230
|
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.OPSQLiteConnection = void 0;
|
|
7
|
-
var _common = require("@powersync/common");
|
|
8
|
-
class OPSQLiteConnection extends _common.BaseObserver {
|
|
9
|
-
constructor(options) {
|
|
10
|
-
super();
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.DB = options.baseDB;
|
|
13
|
-
this.updateBuffer = [];
|
|
14
|
-
this.DB.rollbackHook(() => {
|
|
15
|
-
this.updateBuffer = [];
|
|
16
|
-
});
|
|
17
|
-
this.DB.updateHook(update => {
|
|
18
|
-
this.addTableUpdate(update);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
addTableUpdate(update) {
|
|
22
|
-
let opType;
|
|
23
|
-
switch (update.operation) {
|
|
24
|
-
case 'INSERT':
|
|
25
|
-
opType = _common.RowUpdateType.SQLITE_INSERT;
|
|
26
|
-
break;
|
|
27
|
-
case 'DELETE':
|
|
28
|
-
opType = _common.RowUpdateType.SQLITE_DELETE;
|
|
29
|
-
break;
|
|
30
|
-
case 'UPDATE':
|
|
31
|
-
opType = _common.RowUpdateType.SQLITE_UPDATE;
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
this.updateBuffer.push({
|
|
35
|
-
table: update.table,
|
|
36
|
-
opType,
|
|
37
|
-
rowId: update.rowId
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
flushUpdates() {
|
|
41
|
-
if (!this.updateBuffer.length) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const groupedUpdates = this.updateBuffer.reduce((grouping, update) => {
|
|
45
|
-
const {
|
|
46
|
-
table
|
|
47
|
-
} = update;
|
|
48
|
-
const updateGroup = grouping[table] || (grouping[table] = []);
|
|
49
|
-
updateGroup.push(update);
|
|
50
|
-
return grouping;
|
|
51
|
-
}, {});
|
|
52
|
-
const batchedUpdate = {
|
|
53
|
-
groupedUpdates,
|
|
54
|
-
rawUpdates: this.updateBuffer,
|
|
55
|
-
tables: Object.keys(groupedUpdates)
|
|
56
|
-
};
|
|
57
|
-
this.updateBuffer = [];
|
|
58
|
-
this.iterateListeners(l => l.tablesUpdated?.(batchedUpdate));
|
|
59
|
-
}
|
|
60
|
-
close() {
|
|
61
|
-
return this.DB.close();
|
|
62
|
-
}
|
|
63
|
-
async execute(query, params) {
|
|
64
|
-
const res = await this.DB.execute(query, params);
|
|
65
|
-
return {
|
|
66
|
-
insertId: res.insertId,
|
|
67
|
-
rowsAffected: res.rowsAffected,
|
|
68
|
-
rows: {
|
|
69
|
-
_array: res.rows ?? [],
|
|
70
|
-
length: res.rows?.length ?? 0,
|
|
71
|
-
item: index => res.rows?.[index]
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
async executeRaw(query, params) {
|
|
76
|
-
return await this.DB.executeRaw(query, params);
|
|
77
|
-
}
|
|
78
|
-
async executeBatch(query, params = []) {
|
|
79
|
-
const tuple = [[query, params[0]]];
|
|
80
|
-
params.slice(1).forEach(p => tuple.push([query, p]));
|
|
81
|
-
const result = await this.DB.executeBatch(tuple);
|
|
82
|
-
return {
|
|
83
|
-
rowsAffected: result.rowsAffected ?? 0
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
async getAll(sql, parameters) {
|
|
87
|
-
const result = await this.DB.execute(sql, parameters);
|
|
88
|
-
return result.rows ?? [];
|
|
89
|
-
}
|
|
90
|
-
async getOptional(sql, parameters) {
|
|
91
|
-
const result = await this.DB.execute(sql, parameters);
|
|
92
|
-
return result.rows?.[0] ?? null;
|
|
93
|
-
}
|
|
94
|
-
async get(sql, parameters) {
|
|
95
|
-
const result = await this.getOptional(sql, parameters);
|
|
96
|
-
if (!result) {
|
|
97
|
-
throw new Error('Result set is empty');
|
|
98
|
-
}
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
async refreshSchema() {
|
|
102
|
-
await this.get("PRAGMA table_info('sqlite_master')");
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
exports.OPSQLiteConnection = OPSQLiteConnection;
|
|
106
|
-
//# sourceMappingURL=OPSQLiteConnection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_common","require","OPSQLiteConnection","BaseObserver","constructor","options","DB","baseDB","updateBuffer","rollbackHook","updateHook","update","addTableUpdate","opType","operation","RowUpdateType","SQLITE_INSERT","SQLITE_DELETE","SQLITE_UPDATE","push","table","rowId","flushUpdates","length","groupedUpdates","reduce","grouping","updateGroup","batchedUpdate","rawUpdates","tables","Object","keys","iterateListeners","l","tablesUpdated","close","execute","query","params","res","insertId","rowsAffected","rows","_array","item","index","executeRaw","executeBatch","tuple","slice","forEach","p","result","getAll","sql","parameters","getOptional","get","Error","refreshSchema","exports"],"sourceRoot":"../../../src","sources":["db/OPSQLiteConnection.ts"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AAoBO,MAAMC,kBAAkB,SAASC,oBAAY,CAAoB;EAItEC,WAAWA,CAAWC,OAAkC,EAAE;IACxD,KAAK,CAAC,CAAC;IAAC,KADYA,OAAkC,GAAlCA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C;IAEtD,MAAMC,MAAM,GAAG,MAAM,IAAI,CAAC/C,EAAE,CAAC0C,YAAY,CAACC,KAAK,CAAC;IAChD,OAAO;MACLP,YAAY,EAAEW,MAAM,CAACX,YAAY,IAAI;IACvC,CAAC;EACH;EAEA,MAAMY,MAAMA,CAAIC,GAAW,EAAEC,UAAkB,EAAgB;IAC7D,MAAMH,MAAM,GAAG,MAAM,IAAI,CAAC/C,EAAE,CAAC+B,OAAO,CAACkB,GAAG,EAAEC,UAAU,CAAC;IACrD,OAAQH,MAAM,CAACV,IAAI,IAAI,EAAE;EAC3B;EAEA,MAAMc,WAAWA,CAAIF,GAAW,EAAEC,UAAkB,EAAqB;IACvE,MAAMH,MAAM,GAAG,MAAM,IAAI,CAAC/C,EAAE,CAAC+B,OAAO,CAACkB,GAAG,EAAEC,UAAU,CAAC;IACrD,OAAQH,MAAM,CAACV,IAAI,GAAG,CAAC,CAAC,IAAU,IAAI;EACxC;EAEA,MAAMe,GAAGA,CAAIH,GAAW,EAAEC,UAAkB,EAAc;IACxD,MAAMH,MAAM,GAAG,MAAM,IAAI,CAACI,WAAW,CAACF,GAAG,EAAEC,UAAU,CAAC;IACtD,IAAI,CAACH,MAAM,EAAE;MACX,MAAM,IAAIM,KAAK,CAAC,qBAAqB,CAAC;IACxC;IACA,OAAON,MAAM;EACf;EAEA,MAAMO,aAAaA,CAAA,EAAG;IACpB,MAAM,IAAI,CAACF,GAAG,CAAC,oCAAoC,CAAC;EACtD;AACF;AAACG,OAAA,CAAA3D,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.OPSQLiteDBAdapter = void 0;
|
|
7
|
-
var _opSqlite = require("@op-engineering/op-sqlite");
|
|
8
|
-
var _common = require("@powersync/common");
|
|
9
|
-
var _asyncLock = _interopRequireDefault(require("async-lock"));
|
|
10
|
-
var _reactNative = require("react-native");
|
|
11
|
-
var _OPSQLiteConnection = require("./OPSQLiteConnection.js");
|
|
12
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
/**
|
|
14
|
-
* Adapter for React Native Quick SQLite
|
|
15
|
-
*/
|
|
16
|
-
var LockType = /*#__PURE__*/function (LockType) {
|
|
17
|
-
LockType["READ"] = "read";
|
|
18
|
-
LockType["WRITE"] = "write";
|
|
19
|
-
return LockType;
|
|
20
|
-
}(LockType || {});
|
|
21
|
-
const READ_CONNECTIONS = 5;
|
|
22
|
-
class OPSQLiteDBAdapter extends _common.BaseObserver {
|
|
23
|
-
readQueue = [];
|
|
24
|
-
constructor(options) {
|
|
25
|
-
super();
|
|
26
|
-
this.options = options;
|
|
27
|
-
this.name = this.options.name;
|
|
28
|
-
this.locks = new _asyncLock.default({
|
|
29
|
-
maxPending: Infinity
|
|
30
|
-
});
|
|
31
|
-
this.readConnections = null;
|
|
32
|
-
this.writeConnection = null;
|
|
33
|
-
this.abortController = new AbortController();
|
|
34
|
-
this.initialized = this.init();
|
|
35
|
-
}
|
|
36
|
-
async init() {
|
|
37
|
-
const {
|
|
38
|
-
lockTimeoutMs,
|
|
39
|
-
journalMode,
|
|
40
|
-
journalSizeLimit,
|
|
41
|
-
synchronous,
|
|
42
|
-
cacheSizeKb,
|
|
43
|
-
temporaryStorage
|
|
44
|
-
} = this.options.sqliteOptions;
|
|
45
|
-
const dbFilename = this.options.name;
|
|
46
|
-
this.writeConnection = await this.openConnection(dbFilename);
|
|
47
|
-
const baseStatements = [`PRAGMA busy_timeout = ${lockTimeoutMs}`, `PRAGMA cache_size = -${cacheSizeKb}`, `PRAGMA temp_store = ${temporaryStorage}`];
|
|
48
|
-
const writeConnectionStatements = [...baseStatements, `PRAGMA journal_mode = ${journalMode}`, `PRAGMA journal_size_limit = ${journalSizeLimit}`, `PRAGMA synchronous = ${synchronous}`];
|
|
49
|
-
const readConnectionStatements = [...baseStatements, 'PRAGMA query_only = true'];
|
|
50
|
-
for (const statement of writeConnectionStatements) {
|
|
51
|
-
for (let tries = 0; tries < 30; tries++) {
|
|
52
|
-
try {
|
|
53
|
-
await this.writeConnection.execute(statement);
|
|
54
|
-
break;
|
|
55
|
-
} catch (e) {
|
|
56
|
-
if (e instanceof Error && e.message.includes('database is locked') && tries < 29) {
|
|
57
|
-
continue;
|
|
58
|
-
} else {
|
|
59
|
-
throw e;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Changes should only occur in the write connection
|
|
66
|
-
this.writeConnection.registerListener({
|
|
67
|
-
tablesUpdated: notification => this.iterateListeners(cb => cb.tablesUpdated?.(notification))
|
|
68
|
-
});
|
|
69
|
-
this.readConnections = [];
|
|
70
|
-
for (let i = 0; i < READ_CONNECTIONS; i++) {
|
|
71
|
-
const conn = await this.openConnection(dbFilename);
|
|
72
|
-
for (let statement of readConnectionStatements) {
|
|
73
|
-
await conn.execute(statement);
|
|
74
|
-
}
|
|
75
|
-
this.readConnections.push({
|
|
76
|
-
busy: false,
|
|
77
|
-
connection: conn
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
async openConnection(filenameOverride) {
|
|
82
|
-
const dbFilename = filenameOverride ?? this.options.name;
|
|
83
|
-
const DB = this.openDatabase(dbFilename, this.options.sqliteOptions?.encryptionKey ?? undefined);
|
|
84
|
-
|
|
85
|
-
//Load extensions for all connections
|
|
86
|
-
this.loadAdditionalExtensions(DB);
|
|
87
|
-
this.loadPowerSyncExtension(DB);
|
|
88
|
-
await DB.execute('SELECT powersync_init()');
|
|
89
|
-
return new _OPSQLiteConnection.OPSQLiteConnection({
|
|
90
|
-
baseDB: DB
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
openDatabase(dbFilename, encryptionKey) {
|
|
94
|
-
const openOptions = {
|
|
95
|
-
name: dbFilename
|
|
96
|
-
};
|
|
97
|
-
if (this.options.dbLocation) {
|
|
98
|
-
openOptions.location = this.options.dbLocation;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// If the encryption key is undefined/null when using SQLCipher it will cause the open function to fail
|
|
102
|
-
if (encryptionKey) {
|
|
103
|
-
openOptions.encryptionKey = encryptionKey;
|
|
104
|
-
}
|
|
105
|
-
return (0, _opSqlite.open)(openOptions);
|
|
106
|
-
}
|
|
107
|
-
loadAdditionalExtensions(DB) {
|
|
108
|
-
if (this.options.sqliteOptions?.extensions && this.options.sqliteOptions.extensions.length > 0) {
|
|
109
|
-
for (const extension of this.options.sqliteOptions.extensions) {
|
|
110
|
-
DB.loadExtension(extension.path, extension.entryPoint);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
async loadPowerSyncExtension(DB) {
|
|
115
|
-
if (_reactNative.Platform.OS === 'ios') {
|
|
116
|
-
const libPath = (0, _opSqlite.getDylibPath)('co.powersync.sqlitecore', 'powersync-sqlite-core');
|
|
117
|
-
DB.loadExtension(libPath, 'sqlite3_powersync_init');
|
|
118
|
-
} else {
|
|
119
|
-
DB.loadExtension('libpowersync', 'sqlite3_powersync_init');
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
async close() {
|
|
123
|
-
await this.initialized;
|
|
124
|
-
// Abort any pending operations
|
|
125
|
-
this.abortController.abort();
|
|
126
|
-
this.readQueue = [];
|
|
127
|
-
this.writeConnection.close();
|
|
128
|
-
this.readConnections.forEach(c => c.connection.close());
|
|
129
|
-
}
|
|
130
|
-
async readLock(fn, options) {
|
|
131
|
-
await this.initialized;
|
|
132
|
-
return new Promise(async (resolve, reject) => {
|
|
133
|
-
const execute = async () => {
|
|
134
|
-
// Find an available connection that is not busy
|
|
135
|
-
const availableConnection = this.readConnections.find(conn => !conn.busy);
|
|
136
|
-
|
|
137
|
-
// If we have an available connection, use it
|
|
138
|
-
if (availableConnection) {
|
|
139
|
-
availableConnection.busy = true;
|
|
140
|
-
try {
|
|
141
|
-
resolve(await fn(availableConnection.connection));
|
|
142
|
-
} catch (error) {
|
|
143
|
-
reject(error);
|
|
144
|
-
} finally {
|
|
145
|
-
availableConnection.busy = false;
|
|
146
|
-
// After query execution, process any queued tasks
|
|
147
|
-
this.processQueue();
|
|
148
|
-
}
|
|
149
|
-
} else {
|
|
150
|
-
// If no available connections, add to the queue
|
|
151
|
-
this.readQueue.push(execute);
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
execute();
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
async processQueue() {
|
|
158
|
-
if (this.readQueue.length > 0) {
|
|
159
|
-
const next = this.readQueue.shift();
|
|
160
|
-
if (next) {
|
|
161
|
-
next();
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
async writeLock(fn, options) {
|
|
166
|
-
await this.initialized;
|
|
167
|
-
return new Promise(async (resolve, reject) => {
|
|
168
|
-
try {
|
|
169
|
-
// Set up abort signal listener
|
|
170
|
-
const abortListener = () => {
|
|
171
|
-
reject(new Error('Database connection was closed'));
|
|
172
|
-
};
|
|
173
|
-
this.abortController.signal.addEventListener('abort', abortListener);
|
|
174
|
-
await this.locks.acquire(LockType.WRITE, async () => {
|
|
175
|
-
// Check if operation was aborted before executing
|
|
176
|
-
if (this.abortController.signal.aborted) {
|
|
177
|
-
reject(new Error('Database connection was closed'));
|
|
178
|
-
}
|
|
179
|
-
resolve(await fn(this.writeConnection));
|
|
180
|
-
}, {
|
|
181
|
-
timeout: options?.timeoutMs
|
|
182
|
-
}).then(() => {
|
|
183
|
-
// flush updates once a write lock has been released
|
|
184
|
-
this.writeConnection.flushUpdates();
|
|
185
|
-
}).finally(() => {
|
|
186
|
-
this.abortController.signal.removeEventListener('abort', abortListener);
|
|
187
|
-
});
|
|
188
|
-
} catch (ex) {
|
|
189
|
-
reject(ex);
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
readTransaction(fn, options) {
|
|
194
|
-
return this.readLock(ctx => this.internalTransaction(ctx, fn));
|
|
195
|
-
}
|
|
196
|
-
writeTransaction(fn, options) {
|
|
197
|
-
return this.writeLock(ctx => this.internalTransaction(ctx, fn));
|
|
198
|
-
}
|
|
199
|
-
getAll(sql, parameters) {
|
|
200
|
-
return this.readLock(ctx => ctx.getAll(sql, parameters));
|
|
201
|
-
}
|
|
202
|
-
getOptional(sql, parameters) {
|
|
203
|
-
return this.readLock(ctx => ctx.getOptional(sql, parameters));
|
|
204
|
-
}
|
|
205
|
-
get(sql, parameters) {
|
|
206
|
-
return this.readLock(ctx => ctx.get(sql, parameters));
|
|
207
|
-
}
|
|
208
|
-
execute(query, params) {
|
|
209
|
-
return this.writeLock(ctx => ctx.execute(query, params));
|
|
210
|
-
}
|
|
211
|
-
executeRaw(query, params) {
|
|
212
|
-
return this.writeLock(ctx => ctx.executeRaw(query, params));
|
|
213
|
-
}
|
|
214
|
-
async executeBatch(query, params = []) {
|
|
215
|
-
return this.writeLock(ctx => ctx.executeBatch(query, params));
|
|
216
|
-
}
|
|
217
|
-
async internalTransaction(connection, fn) {
|
|
218
|
-
let finalized = false;
|
|
219
|
-
const commit = async () => {
|
|
220
|
-
if (finalized) {
|
|
221
|
-
return {
|
|
222
|
-
rowsAffected: 0
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
finalized = true;
|
|
226
|
-
return connection.execute('COMMIT');
|
|
227
|
-
};
|
|
228
|
-
const rollback = async () => {
|
|
229
|
-
if (finalized) {
|
|
230
|
-
return {
|
|
231
|
-
rowsAffected: 0
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
finalized = true;
|
|
235
|
-
return connection.execute('ROLLBACK');
|
|
236
|
-
};
|
|
237
|
-
try {
|
|
238
|
-
await connection.execute('BEGIN');
|
|
239
|
-
const result = await fn({
|
|
240
|
-
execute: (query, params) => connection.execute(query, params),
|
|
241
|
-
executeRaw: (query, params) => connection.executeRaw(query, params),
|
|
242
|
-
get: (query, params) => connection.get(query, params),
|
|
243
|
-
getAll: (query, params) => connection.getAll(query, params),
|
|
244
|
-
getOptional: (query, params) => connection.getOptional(query, params),
|
|
245
|
-
commit,
|
|
246
|
-
rollback
|
|
247
|
-
});
|
|
248
|
-
await commit();
|
|
249
|
-
return result;
|
|
250
|
-
} catch (ex) {
|
|
251
|
-
try {
|
|
252
|
-
await rollback();
|
|
253
|
-
} catch (ex2) {
|
|
254
|
-
// In rare cases, a rollback may fail.
|
|
255
|
-
// Safe to ignore.
|
|
256
|
-
}
|
|
257
|
-
throw ex;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
async refreshSchema() {
|
|
261
|
-
await this.initialized;
|
|
262
|
-
await this.writeConnection.refreshSchema();
|
|
263
|
-
if (this.readConnections) {
|
|
264
|
-
for (let readConnection of this.readConnections) {
|
|
265
|
-
await readConnection.connection.refreshSchema();
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
exports.OPSQLiteDBAdapter = OPSQLiteDBAdapter;
|
|
271
|
-
//# sourceMappingURL=OPSqliteAdapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_opSqlite","require","_common","_asyncLock","_interopRequireDefault","_reactNative","_OPSQLiteConnection","e","__esModule","default","LockType","READ_CONNECTIONS","OPSQLiteDBAdapter","BaseObserver","readQueue","constructor","options","name","locks","Lock","maxPending","Infinity","readConnections","writeConnection","abortController","AbortController","initialized","init","lockTimeoutMs","journalMode","journalSizeLimit","synchronous","cacheSizeKb","temporaryStorage","sqliteOptions","dbFilename","openConnection","baseStatements","writeConnectionStatements","readConnectionStatements","statement","tries","execute","Error","message","includes","registerListener","tablesUpdated","notification","iterateListeners","cb","i","conn","push","busy","connection","filenameOverride","DB","openDatabase","encryptionKey","undefined","loadAdditionalExtensions","loadPowerSyncExtension","OPSQLiteConnection","baseDB","openOptions","dbLocation","location","open","extensions","length","extension","loadExtension","path","entryPoint","Platform","OS","libPath","getDylibPath","close","abort","forEach","c","readLock","fn","Promise","resolve","reject","availableConnection","find","error","processQueue","next","shift","writeLock","abortListener","signal","addEventListener","acquire","WRITE","aborted","timeout","timeoutMs","then","flushUpdates","finally","removeEventListener","ex","readTransaction","ctx","internalTransaction","writeTransaction","getAll","sql","parameters","getOptional","get","query","params","executeRaw","executeBatch","finalized","commit","rowsAffected","rollback","result","ex2","refreshSchema","readConnection","exports"],"sourceRoot":"../../../src","sources":["db/OPSqliteAdapter.ts"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,mBAAA,GAAAL,OAAA;AAA0D,SAAAG,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAG1D;AACA;AACA;AAFA,IASKG,QAAQ,0BAARA,QAAQ;EAARA,QAAQ;EAARA,QAAQ;EAAA,OAARA,QAAQ;AAAA,EAARA,QAAQ;AAKb,MAAMC,gBAAgB,GAAG,CAAC;AAEnB,MAAMC,iBAAiB,SAASC,oBAAY,CAAyC;EAUlFC,SAAS,GAAsB,EAAE;EAGzCC,WAAWA,CAAWC,OAA+B,EAAE;IACrD,KAAK,CAAC,CAAC;IAAC,KADYA,OAA+B,GAA/BA,OAA+B;IAEnD,IAAI,CAACC,IAAI,GAAG,IAAI,CAACD,OAAO,CAACC,IAAI;IAE7B,IAAI,CAACC,KAAK,GAAG,IAAIC,kBAAI,CAAC;MAAEC,UAAU,EAAEC;IAAS,CAAC,CAAC;IAC/C,IAAI,CAACC,eAAe,GAAG,IAAI;IAC3B,IAAI,CAACC,eAAe,GAAG,IAAI;IAC3B,IAAI,CAACC,eAAe,GAAG,IAAIC,eAAe,CAAC,CAA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CAAC1G,eAAe,EAAE;QAC/C,MAAM0G,cAAc,CAACzE,UAAU,CAACwE,aAAa,CAAC,CAAC;MACjD;IACF;EACF;AACF;AAACE,OAAA,CAAArH,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.OPSqliteOpenFactory = void 0;
|
|
7
|
-
var _OPSqliteAdapter = require("./OPSqliteAdapter.js");
|
|
8
|
-
var _SqliteOptions = require("./SqliteOptions.js");
|
|
9
|
-
class OPSqliteOpenFactory {
|
|
10
|
-
constructor(options) {
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.sqliteOptions = {
|
|
13
|
-
..._SqliteOptions.DEFAULT_SQLITE_OPTIONS,
|
|
14
|
-
...this.options.sqliteOptions
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
openDB() {
|
|
18
|
-
return new _OPSqliteAdapter.OPSQLiteDBAdapter({
|
|
19
|
-
name: this.options.dbFilename,
|
|
20
|
-
dbLocation: this.options.dbLocation,
|
|
21
|
-
sqliteOptions: this.sqliteOptions
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.OPSqliteOpenFactory = OPSqliteOpenFactory;
|
|
26
|
-
//# sourceMappingURL=OPSqliteDBOpenFactory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_OPSqliteAdapter","require","_SqliteOptions","OPSqliteOpenFactory","constructor","options","sqliteOptions","DEFAULT_SQLITE_OPTIONS","openDB","OPSQLiteDBAdapter","name","dbFilename","dbLocation","exports"],"sourceRoot":"../../../src","sources":["db/OPSqliteDBOpenFactory.ts"],"mappings":";;;;;;AACA,IAAAA,gBAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAKO,MAAME,mBAAmB,CAA2B;EAGzDC,WAAWA,CAAWC,OAAmC,EAAE;IAAA,KAArCA,OAAmC,GAAnCA,OAAmC;IACvD,IAAI,CAACC,aAAa,GAAG;MACnB,GAAGC,qCAAsB;MACzB,GAAG,IAAI,CAACF,OAAO,CAACC;IAClB,CAAC;EACH;EAEAE,MAAMA,CAAA,EAAc;IAClB,OAAO,IAAIC,kCAAiB,CAAC;MAC3BC,IAAI,EAAE,IAAI,CAACL,OAAO,CAACM,UAAU;MAC7BC,UAAU,EAAE,IAAI,CAACP,OAAO,CAACO,UAAU;MACnCN,aAAa,EAAE,IAAI,CAACA;IACtB,CAAC,CAAC;EACJ;AACF;AAACO,OAAA,CAAAV,mBAAA,GAAAA,mBAAA","ignoreList":[]}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.TemporaryStorageOption = exports.DEFAULT_SQLITE_OPTIONS = void 0;
|
|
7
|
-
let TemporaryStorageOption = exports.TemporaryStorageOption = /*#__PURE__*/function (TemporaryStorageOption) {
|
|
8
|
-
TemporaryStorageOption["MEMORY"] = "memory";
|
|
9
|
-
TemporaryStorageOption["FILESYSTEM"] = "file";
|
|
10
|
-
return TemporaryStorageOption;
|
|
11
|
-
}({}); // SQLite journal mode. Set on the primary connection.
|
|
12
|
-
// This library is written with WAL mode in mind - other modes may cause
|
|
13
|
-
// unexpected locking behavior.
|
|
14
|
-
var SqliteJournalMode = /*#__PURE__*/function (SqliteJournalMode) {
|
|
15
|
-
// Use a write-ahead log instead of a rollback journal.
|
|
16
|
-
// This provides good performance and concurrency.
|
|
17
|
-
SqliteJournalMode["wal"] = "WAL";
|
|
18
|
-
SqliteJournalMode["delete"] = "DELETE";
|
|
19
|
-
SqliteJournalMode["truncate"] = "TRUNCATE";
|
|
20
|
-
SqliteJournalMode["persist"] = "PERSIST";
|
|
21
|
-
SqliteJournalMode["memory"] = "MEMORY";
|
|
22
|
-
SqliteJournalMode["off"] = "OFF";
|
|
23
|
-
return SqliteJournalMode;
|
|
24
|
-
}(SqliteJournalMode || {}); // SQLite file commit mode.
|
|
25
|
-
var SqliteSynchronous = /*#__PURE__*/function (SqliteSynchronous) {
|
|
26
|
-
SqliteSynchronous["normal"] = "NORMAL";
|
|
27
|
-
SqliteSynchronous["full"] = "FULL";
|
|
28
|
-
SqliteSynchronous["off"] = "OFF";
|
|
29
|
-
return SqliteSynchronous;
|
|
30
|
-
}(SqliteSynchronous || {});
|
|
31
|
-
const DEFAULT_SQLITE_OPTIONS = exports.DEFAULT_SQLITE_OPTIONS = {
|
|
32
|
-
journalMode: SqliteJournalMode.wal,
|
|
33
|
-
synchronous: SqliteSynchronous.normal,
|
|
34
|
-
journalSizeLimit: 6 * 1024 * 1024,
|
|
35
|
-
cacheSizeKb: 50 * 1024,
|
|
36
|
-
temporaryStorage: TemporaryStorageOption.MEMORY,
|
|
37
|
-
lockTimeoutMs: 30000,
|
|
38
|
-
encryptionKey: null,
|
|
39
|
-
extensions: []
|
|
40
|
-
};
|
|
41
|
-
//# sourceMappingURL=SqliteOptions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["TemporaryStorageOption","exports","SqliteJournalMode","SqliteSynchronous","DEFAULT_SQLITE_OPTIONS","journalMode","wal","synchronous","normal","journalSizeLimit","cacheSizeKb","temporaryStorage","MEMORY","lockTimeoutMs","encryptionKey","extensions"],"sourceRoot":"../../../src","sources":["db/SqliteOptions.ts"],"mappings":";;;;;;IAyDYA,sBAAsB,GAAAC,OAAA,CAAAD,sBAAA,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA,OAKlC;AACA;AACA;AAAA,IACKE,iBAAiB,0BAAjBA,iBAAiB;EACpB;EACA;EAFGA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAA,OAAjBA,iBAAiB;AAAA,EAAjBA,iBAAiB,SAWtB;AAAA,IACKC,iBAAiB,0BAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAA,OAAjBA,iBAAiB;AAAA,EAAjBA,iBAAiB;AAMf,MAAMC,sBAA+C,GAAAH,OAAA,CAAAG,sBAAA,GAAG;EAC7DC,WAAW,EAAEH,iBAAiB,CAACI,GAAG;EAClCC,WAAW,EAAEJ,iBAAiB,CAACK,MAAM;EACrCC,gBAAgB,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI;EACjCC,WAAW,EAAE,EAAE,GAAG,IAAI;EACtBC,gBAAgB,EAAEX,sBAAsB,CAACY,MAAM;EAC/CC,aAAa,EAAE,KAAK;EACpBC,aAAa,EAAE,IAAI;EACnBC,UAAU,EAAE;AACd,CAAC","ignoreList":[]}
|
package/lib/commonjs/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "OPSQLiteOpenFactoryOptions", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _OPSqliteDBOpenFactory.OPSQLiteOpenFactoryOptions;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "OPSqliteOpenFactory", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _OPSqliteDBOpenFactory.OPSqliteOpenFactory;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
var _OPSqliteDBOpenFactory = require("./db/OPSqliteDBOpenFactory.js");
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_OPSqliteDBOpenFactory","require"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,sBAAA,GAAAC,OAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"commonjs"}
|