@powersync/op-sqlite 0.0.0-dev-20241107150304 → 0.0.0-dev-20250121114305
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/lib/{typescript/commonjs/src → src}/db/OPSQLiteConnection.d.ts +11 -2
- package/lib/src/db/OPSQLiteConnection.js +118 -0
- package/lib/{typescript/commonjs/src → src}/db/OPSqliteAdapter.d.ts +3 -2
- package/lib/src/db/OPSqliteAdapter.js +267 -0
- package/lib/{typescript/commonjs/src → src}/db/OPSqliteDBOpenFactory.d.ts +0 -1
- package/lib/src/db/OPSqliteDBOpenFactory.js +15 -0
- package/lib/{typescript/module/src → src}/db/SqliteOptions.d.ts +9 -2
- package/lib/src/db/SqliteOptions.js +29 -0
- package/lib/{typescript/commonjs/src → src}/index.d.ts +0 -2
- package/lib/src/index.js +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +11 -80
- package/android/build.gradle +0 -124
- package/android/gradle.properties +0 -5
- package/android/src/main/AndroidManifest.xml +0 -3
- package/android/src/main/AndroidManifestNew.xml +0 -2
- package/android/src/main/java/com/powersync/opsqlite/PowerSyncOpSqliteModule.kt +0 -25
- package/android/src/main/java/com/powersync/opsqlite/PowerSyncOpSqlitePackage.kt +0 -35
- package/android/src/newarch/PowerSyncOpSqliteSpec.kt +0 -7
- package/android/src/oldarch/PowerSyncOpSqliteSpec.kt +0 -11
- package/ios/PowerSyncOpSqlite.h +0 -5
- package/ios/PowerSyncOpSqlite.mm +0 -11
- package/lib/commonjs/NativePowerSyncOpSqlite.js +0 -9
- package/lib/commonjs/NativePowerSyncOpSqlite.js.map +0 -1
- package/lib/commonjs/db/OPSQLiteConnection.js +0 -77
- package/lib/commonjs/db/OPSQLiteConnection.js.map +0 -1
- package/lib/commonjs/db/OPSqliteAdapter.js +0 -234
- 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 -32
- package/lib/commonjs/db/SqliteOptions.js.map +0 -1
- package/lib/commonjs/index.js +0 -35
- package/lib/commonjs/index.js.map +0 -1
- package/lib/module/NativePowerSyncOpSqlite.js +0 -5
- package/lib/module/NativePowerSyncOpSqlite.js.map +0 -1
- package/lib/module/db/OPSQLiteConnection.js +0 -72
- package/lib/module/db/OPSQLiteConnection.js.map +0 -1
- package/lib/module/db/OPSqliteAdapter.js +0 -229
- 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 -28
- package/lib/module/db/SqliteOptions.js.map +0 -1
- package/lib/module/index.js +0 -19
- package/lib/module/index.js.map +0 -1
- package/lib/typescript/commonjs/package.json +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/commonjs/src/db/OPSQLiteConnection.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/db/OPSqliteAdapter.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/db/OPSqliteDBOpenFactory.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/db/SqliteOptions.d.ts +0 -44
- package/lib/typescript/commonjs/src/db/SqliteOptions.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/index.d.ts.map +0 -1
- package/lib/typescript/commonjs/tsconfig.build.tsbuildinfo +0 -1
- package/lib/typescript/module/package.json +0 -1
- package/lib/typescript/module/src/NativePowerSyncOpSqlite.d.ts +0 -7
- package/lib/typescript/module/src/NativePowerSyncOpSqlite.d.ts.map +0 -1
- package/lib/typescript/module/src/db/OPSQLiteConnection.d.ts +0 -17
- package/lib/typescript/module/src/db/OPSQLiteConnection.d.ts.map +0 -1
- package/lib/typescript/module/src/db/OPSqliteAdapter.d.ts +0 -43
- 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.map +0 -1
- package/lib/typescript/module/src/index.d.ts +0 -3
- package/lib/typescript/module/src/index.d.ts.map +0 -1
- package/lib/typescript/module/tsconfig.build.tsbuildinfo +0 -1
- package/powersync-op-sqlite.podspec +0 -26
- package/src/NativePowerSyncOpSqlite.ts +0 -8
- package/src/db/OPSQLiteConnection.ts +0 -82
- package/src/db/OPSqliteAdapter.ts +0 -274
- package/src/db/OPSqliteDBOpenFactory.ts +0 -25
- package/src/db/SqliteOptions.ts +0 -61
- package/src/index.ts +0 -30
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.OPSQLiteDBAdapter = void 0;
|
|
7
|
-
var _common = require("@powersync/common");
|
|
8
|
-
var _opSqlite = require("@op-engineering/op-sqlite");
|
|
9
|
-
var _asyncLock = _interopRequireDefault(require("async-lock"));
|
|
10
|
-
var _OPSQLiteConnection = require("./OPSQLiteConnection.js");
|
|
11
|
-
var _reactNative = require("react-native");
|
|
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
|
-
this.readConnections = null;
|
|
30
|
-
this.writeConnection = null;
|
|
31
|
-
this.initialized = this.init();
|
|
32
|
-
}
|
|
33
|
-
async init() {
|
|
34
|
-
const {
|
|
35
|
-
lockTimeoutMs,
|
|
36
|
-
journalMode,
|
|
37
|
-
journalSizeLimit,
|
|
38
|
-
synchronous,
|
|
39
|
-
encryptionKey
|
|
40
|
-
} = this.options.sqliteOptions;
|
|
41
|
-
const dbFilename = this.options.name;
|
|
42
|
-
this.writeConnection = await this.openConnection(dbFilename);
|
|
43
|
-
const statements = [`PRAGMA busy_timeout = ${lockTimeoutMs}`, `PRAGMA journal_mode = ${journalMode}`, `PRAGMA journal_size_limit = ${journalSizeLimit}`, `PRAGMA synchronous = ${synchronous}`];
|
|
44
|
-
for (const statement of statements) {
|
|
45
|
-
for (let tries = 0; tries < 30; tries++) {
|
|
46
|
-
try {
|
|
47
|
-
await this.writeConnection.execute(statement);
|
|
48
|
-
break;
|
|
49
|
-
} catch (e) {
|
|
50
|
-
if (e instanceof Error && e.message.includes('database is locked') && tries < 29) {
|
|
51
|
-
continue;
|
|
52
|
-
} else {
|
|
53
|
-
throw e;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Changes should only occur in the write connection
|
|
60
|
-
this.writeConnection.registerListener({
|
|
61
|
-
tablesUpdated: notification => this.iterateListeners(cb => cb.tablesUpdated?.(notification))
|
|
62
|
-
});
|
|
63
|
-
this.readConnections = [];
|
|
64
|
-
for (let i = 0; i < READ_CONNECTIONS; i++) {
|
|
65
|
-
// Workaround to create read-only connections
|
|
66
|
-
let dbName = './'.repeat(i + 1) + dbFilename;
|
|
67
|
-
const conn = await this.openConnection(dbName);
|
|
68
|
-
await conn.execute('PRAGMA query_only = true');
|
|
69
|
-
this.readConnections.push({
|
|
70
|
-
busy: false,
|
|
71
|
-
connection: conn
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
async openConnection(filenameOverride) {
|
|
76
|
-
const dbFilename = filenameOverride ?? this.options.name;
|
|
77
|
-
const DB = this.openDatabase(dbFilename, this.options.sqliteOptions.encryptionKey);
|
|
78
|
-
|
|
79
|
-
//Load extension for all connections
|
|
80
|
-
this.loadExtension(DB);
|
|
81
|
-
await DB.execute('SELECT powersync_init()');
|
|
82
|
-
return new _OPSQLiteConnection.OPSQLiteConnection({
|
|
83
|
-
baseDB: DB
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
getDbLocation(dbLocation) {
|
|
87
|
-
if (_reactNative.Platform.OS === 'ios') {
|
|
88
|
-
return dbLocation ?? _opSqlite.IOS_LIBRARY_PATH;
|
|
89
|
-
} else {
|
|
90
|
-
return dbLocation ?? _opSqlite.ANDROID_DATABASE_PATH;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
openDatabase(dbFilename, encryptionKey) {
|
|
94
|
-
//This is needed because an undefined/null dbLocation will cause the open function to fail
|
|
95
|
-
const location = this.getDbLocation(this.options.dbLocation);
|
|
96
|
-
//Simarlily if the encryption key is undefined/null when using SQLCipher it will cause the open function to fail
|
|
97
|
-
if (encryptionKey) {
|
|
98
|
-
return (0, _opSqlite.open)({
|
|
99
|
-
name: dbFilename,
|
|
100
|
-
location: location,
|
|
101
|
-
encryptionKey: encryptionKey
|
|
102
|
-
});
|
|
103
|
-
} else {
|
|
104
|
-
return (0, _opSqlite.open)({
|
|
105
|
-
name: dbFilename,
|
|
106
|
-
location: location
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
loadExtension(DB) {
|
|
111
|
-
if (_reactNative.Platform.OS === 'ios') {
|
|
112
|
-
const bundlePath = _reactNative.NativeModules.PowerSyncOpSqlite.getBundlePath();
|
|
113
|
-
const libPath = `${bundlePath}/Frameworks/powersync-sqlite-core.framework/powersync-sqlite-core`;
|
|
114
|
-
DB.loadExtension(libPath, 'sqlite3_powersync_init');
|
|
115
|
-
} else {
|
|
116
|
-
DB.loadExtension('libpowersync', 'sqlite3_powersync_init');
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
close() {
|
|
120
|
-
this.initialized.then(() => {
|
|
121
|
-
this.writeConnection.close();
|
|
122
|
-
this.readConnections.forEach(c => c.connection.close());
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
async readLock(fn, options) {
|
|
126
|
-
await this.initialized;
|
|
127
|
-
return new Promise(async (resolve, reject) => {
|
|
128
|
-
const execute = async () => {
|
|
129
|
-
// Find an available connection that is not busy
|
|
130
|
-
const availableConnection = this.readConnections.find(conn => !conn.busy);
|
|
131
|
-
|
|
132
|
-
// If we have an available connection, use it
|
|
133
|
-
if (availableConnection) {
|
|
134
|
-
availableConnection.busy = true;
|
|
135
|
-
try {
|
|
136
|
-
resolve(await fn(availableConnection.connection));
|
|
137
|
-
} catch (error) {
|
|
138
|
-
reject(error);
|
|
139
|
-
} finally {
|
|
140
|
-
availableConnection.busy = false;
|
|
141
|
-
// After query execution, process any queued tasks
|
|
142
|
-
this.processQueue();
|
|
143
|
-
}
|
|
144
|
-
} else {
|
|
145
|
-
// If no available connections, add to the queue
|
|
146
|
-
this.readQueue.push(execute);
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
execute();
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
async processQueue() {
|
|
153
|
-
if (this.readQueue.length > 0) {
|
|
154
|
-
const next = this.readQueue.shift();
|
|
155
|
-
if (next) {
|
|
156
|
-
next();
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
async writeLock(fn, options) {
|
|
161
|
-
await this.initialized;
|
|
162
|
-
return new Promise(async (resolve, reject) => {
|
|
163
|
-
try {
|
|
164
|
-
await this.locks.acquire(LockType.WRITE, async () => {
|
|
165
|
-
resolve(await fn(this.writeConnection));
|
|
166
|
-
}, {
|
|
167
|
-
timeout: options?.timeoutMs
|
|
168
|
-
});
|
|
169
|
-
} catch (ex) {
|
|
170
|
-
reject(ex);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
readTransaction(fn, options) {
|
|
175
|
-
return this.readLock(ctx => this.internalTransaction(ctx, fn));
|
|
176
|
-
}
|
|
177
|
-
writeTransaction(fn, options) {
|
|
178
|
-
return this.writeLock(ctx => this.internalTransaction(ctx, fn));
|
|
179
|
-
}
|
|
180
|
-
getAll(sql, parameters) {
|
|
181
|
-
return this.readLock(ctx => ctx.getAll(sql, parameters));
|
|
182
|
-
}
|
|
183
|
-
getOptional(sql, parameters) {
|
|
184
|
-
return this.readLock(ctx => ctx.getOptional(sql, parameters));
|
|
185
|
-
}
|
|
186
|
-
get(sql, parameters) {
|
|
187
|
-
return this.readLock(ctx => ctx.get(sql, parameters));
|
|
188
|
-
}
|
|
189
|
-
execute(query, params) {
|
|
190
|
-
return this.writeLock(ctx => ctx.execute(query, params));
|
|
191
|
-
}
|
|
192
|
-
async executeBatch(query, params = []) {
|
|
193
|
-
return this.writeLock(ctx => ctx.executeBatch(query, params));
|
|
194
|
-
}
|
|
195
|
-
async internalTransaction(connection, fn) {
|
|
196
|
-
let finalized = false;
|
|
197
|
-
const commit = async () => {
|
|
198
|
-
if (finalized) {
|
|
199
|
-
return {
|
|
200
|
-
rowsAffected: 0
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
finalized = true;
|
|
204
|
-
return connection.execute('COMMIT');
|
|
205
|
-
};
|
|
206
|
-
const rollback = async () => {
|
|
207
|
-
if (finalized) {
|
|
208
|
-
return {
|
|
209
|
-
rowsAffected: 0
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
finalized = true;
|
|
213
|
-
return connection.execute('ROLLBACK');
|
|
214
|
-
};
|
|
215
|
-
try {
|
|
216
|
-
await connection.execute('BEGIN');
|
|
217
|
-
const result = await fn({
|
|
218
|
-
execute: (query, params) => connection.execute(query, params),
|
|
219
|
-
get: (query, params) => connection.get(query, params),
|
|
220
|
-
getAll: (query, params) => connection.getAll(query, params),
|
|
221
|
-
getOptional: (query, params) => connection.getOptional(query, params),
|
|
222
|
-
commit,
|
|
223
|
-
rollback
|
|
224
|
-
});
|
|
225
|
-
await commit();
|
|
226
|
-
return result;
|
|
227
|
-
} catch (ex) {
|
|
228
|
-
await rollback();
|
|
229
|
-
throw ex;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
exports.OPSQLiteDBAdapter = OPSQLiteDBAdapter;
|
|
234
|
-
//# sourceMappingURL=OPSqliteAdapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_common","require","_opSqlite","_asyncLock","_interopRequireDefault","_OPSQLiteConnection","_reactNative","e","__esModule","default","LockType","READ_CONNECTIONS","OPSQLiteDBAdapter","BaseObserver","readQueue","constructor","options","name","locks","Lock","readConnections","writeConnection","initialized","init","lockTimeoutMs","journalMode","journalSizeLimit","synchronous","encryptionKey","sqliteOptions","dbFilename","openConnection","statements","statement","tries","execute","Error","message","includes","registerListener","tablesUpdated","notification","iterateListeners","cb","i","dbName","repeat","conn","push","busy","connection","filenameOverride","DB","openDatabase","loadExtension","OPSQLiteConnection","baseDB","getDbLocation","dbLocation","Platform","OS","IOS_LIBRARY_PATH","ANDROID_DATABASE_PATH","location","open","bundlePath","NativeModules","PowerSyncOpSqlite","getBundlePath","libPath","close","then","forEach","c","readLock","fn","Promise","resolve","reject","availableConnection","find","error","processQueue","length","next","shift","writeLock","acquire","WRITE","timeout","timeoutMs","ex","readTransaction","ctx","internalTransaction","writeTransaction","getAll","sql","parameters","getOptional","get","query","params","executeBatch","finalized","commit","rowsAffected","rollback","result","exports"],"sourceRoot":"../../../src","sources":["db/OPSq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OAAO,EAAEA,CAACkE,KAAK,EAAEC,MAAM,KAAKpD,UAAU,CAACf,OAAO,CAACkE,KAAK,EAAEC,MAAM,CAAC;QAC7DF,GAAG,EAAEA,CAACC,KAAK,EAAEC,MAAM,KAAKpD,UAAU,CAACkD,GAAG,CAACC,KAAK,EAAEC,MAAM,CAAC;QACrDN,MAAM,EAAEA,CAACK,KAAK,EAAEC,MAAM,KAAKpD,UAAU,CAAC8C,MAAM,CAACK,KAAK,EAAEC,MAAM,CAAC;QAC3DH,WAAW,EAAEA,CAACE,KAAK,EAAEC,MAAM,KAAKpD,UAAU,CAACiD,WAAW,CAACE,KAAK,EAAEC,MAAM,CAAC;QACrEG,MAAM;QACNE;MACF,CAAC,CAAC;MACF,MAAMF,MAAM,CAAC,CAAC;MACd,OAAOG,MAAM;IACf,CAAC,CAAC,OAAOjB,EAAE,EAAE;MACX,MAAMgB,QAAQ,CAAC,CAAC;MAChB,MAAMhB,EAAE;IACV;EACF;AACF;AAACkB,OAAA,CAAAjG,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,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.DEFAULT_SQLITE_OPTIONS = void 0;
|
|
7
|
-
// SQLite journal mode. Set on the primary connection.
|
|
8
|
-
// This library is written with WAL mode in mind - other modes may cause
|
|
9
|
-
// unexpected locking behavior.
|
|
10
|
-
var SqliteJournalMode = /*#__PURE__*/function (SqliteJournalMode) {
|
|
11
|
-
SqliteJournalMode["wal"] = "WAL";
|
|
12
|
-
SqliteJournalMode["delete"] = "DELETE";
|
|
13
|
-
SqliteJournalMode["truncate"] = "TRUNCATE";
|
|
14
|
-
SqliteJournalMode["persist"] = "PERSIST";
|
|
15
|
-
SqliteJournalMode["memory"] = "MEMORY";
|
|
16
|
-
SqliteJournalMode["off"] = "OFF";
|
|
17
|
-
return SqliteJournalMode;
|
|
18
|
-
}(SqliteJournalMode || {}); // SQLite file commit mode.
|
|
19
|
-
var SqliteSynchronous = /*#__PURE__*/function (SqliteSynchronous) {
|
|
20
|
-
SqliteSynchronous["normal"] = "NORMAL";
|
|
21
|
-
SqliteSynchronous["full"] = "FULL";
|
|
22
|
-
SqliteSynchronous["off"] = "OFF";
|
|
23
|
-
return SqliteSynchronous;
|
|
24
|
-
}(SqliteSynchronous || {});
|
|
25
|
-
const DEFAULT_SQLITE_OPTIONS = exports.DEFAULT_SQLITE_OPTIONS = {
|
|
26
|
-
journalMode: SqliteJournalMode.wal,
|
|
27
|
-
synchronous: SqliteSynchronous.normal,
|
|
28
|
-
journalSizeLimit: 6 * 1024 * 1024,
|
|
29
|
-
lockTimeoutMs: 30000,
|
|
30
|
-
encryptionKey: null
|
|
31
|
-
};
|
|
32
|
-
//# sourceMappingURL=SqliteOptions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["SqliteJournalMode","SqliteSynchronous","DEFAULT_SQLITE_OPTIONS","exports","journalMode","wal","synchronous","normal","journalSizeLimit","lockTimeoutMs","encryptionKey"],"sourceRoot":"../../../src","sources":["db/SqliteOptions.ts"],"mappings":";;;;;;AAiCA;AACA;AACA;AAAA,IACKA,iBAAiB,0BAAjBA,iBAAiB;EAAjBA,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,GAAAC,OAAA,CAAAD,sBAAA,GAAG;EAC7DE,WAAW,EAAEJ,iBAAiB,CAACK,GAAG;EAClCC,WAAW,EAAEL,iBAAiB,CAACM,MAAM;EACrCC,gBAAgB,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI;EACjCC,aAAa,EAAE,KAAK;EACpBC,aAAa,EAAE;AACjB,CAAC","ignoreList":[]}
|
package/lib/commonjs/index.js
DELETED
|
@@ -1,35 +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
|
-
exports.getBundlePath = getBundlePath;
|
|
19
|
-
var _reactNative = require("react-native");
|
|
20
|
-
var _OPSqliteDBOpenFactory = require("./db/OPSqliteDBOpenFactory.js");
|
|
21
|
-
const LINKING_ERROR = `The package '@powersync/op-sqlite' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
|
|
22
|
-
ios: "- You have run 'pod install'\n",
|
|
23
|
-
default: ''
|
|
24
|
-
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
25
|
-
const isTurboModuleEnabled = global.__turboModuleProxy != null;
|
|
26
|
-
const PowerSyncOpSqliteModule = isTurboModuleEnabled ? require('./NativePowerSyncOpSqlite').default : _reactNative.NativeModules.PowerSyncOpSqlite;
|
|
27
|
-
const PowerSyncOpSqlite = PowerSyncOpSqliteModule ? PowerSyncOpSqliteModule : new Proxy({}, {
|
|
28
|
-
get() {
|
|
29
|
-
throw new Error(LINKING_ERROR);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
function getBundlePath() {
|
|
33
|
-
return PowerSyncOpSqlite.getBundlePath();
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_OPSqliteDBOpenFactory","LINKING_ERROR","Platform","select","ios","default","isTurboModuleEnabled","global","__turboModuleProxy","PowerSyncOpSqliteModule","NativeModules","PowerSyncOpSqlite","Proxy","get","Error","getBundlePath"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AA6BA,IAAAC,sBAAA,GAAAD,OAAA;AA3BA,MAAME,aAAa,GACjB,+EAA+E,GAC/EC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,oBAAoB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAE9D,MAAMC,uBAAuB,GAAGH,oBAAoB,GAChDP,OAAO,CAAC,2BAA2B,CAAC,CAACM,OAAO,GAC5CK,0BAAa,CAACC,iBAAiB;AAEnC,MAAMA,iBAAiB,GAAGF,uBAAuB,GAC7CA,uBAAuB,GACvB,IAAIG,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACb,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEE,SAASc,aAAaA,CAAA,EAAW;EACtC,OAAOJ,iBAAiB,CAACI,aAAa,CAAC,CAAC;AAC1C","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,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { BaseObserver, RowUpdateType } from '@powersync/common';
|
|
4
|
-
export class OPSQLiteConnection extends BaseObserver {
|
|
5
|
-
constructor(options) {
|
|
6
|
-
super();
|
|
7
|
-
this.options = options;
|
|
8
|
-
this.DB = options.baseDB;
|
|
9
|
-
|
|
10
|
-
// link table update commands
|
|
11
|
-
this.DB.updateHook(update => {
|
|
12
|
-
this.iterateListeners(cb => {
|
|
13
|
-
let opType;
|
|
14
|
-
switch (update.operation) {
|
|
15
|
-
case 'INSERT':
|
|
16
|
-
opType = RowUpdateType.SQLITE_INSERT;
|
|
17
|
-
break;
|
|
18
|
-
case 'DELETE':
|
|
19
|
-
opType = RowUpdateType.SQLITE_DELETE;
|
|
20
|
-
break;
|
|
21
|
-
case 'UPDATE':
|
|
22
|
-
opType = RowUpdateType.SQLITE_UPDATE;
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
cb.tablesUpdated?.({
|
|
26
|
-
table: update.table,
|
|
27
|
-
opType,
|
|
28
|
-
rowId: update.rowId
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
close() {
|
|
34
|
-
return this.DB.close();
|
|
35
|
-
}
|
|
36
|
-
async execute(query, params) {
|
|
37
|
-
const res = await this.DB.execute(query, params);
|
|
38
|
-
return {
|
|
39
|
-
insertId: res.insertId,
|
|
40
|
-
rowsAffected: res.rowsAffected,
|
|
41
|
-
rows: {
|
|
42
|
-
_array: res.rows ?? [],
|
|
43
|
-
length: res.rows?.length ?? 0,
|
|
44
|
-
item: index => res.rows?.[index]
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
async executeBatch(query, params = []) {
|
|
49
|
-
const tuple = [[query, params[0]]];
|
|
50
|
-
params.slice(1).forEach(p => tuple.push([query, p]));
|
|
51
|
-
const result = await this.DB.executeBatch(tuple);
|
|
52
|
-
return {
|
|
53
|
-
rowsAffected: result.rowsAffected ?? 0
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
async getAll(sql, parameters) {
|
|
57
|
-
const result = await this.DB.execute(sql, parameters);
|
|
58
|
-
return result.rows ?? [];
|
|
59
|
-
}
|
|
60
|
-
async getOptional(sql, parameters) {
|
|
61
|
-
const result = await this.DB.execute(sql, parameters);
|
|
62
|
-
return result.rows?.[0] ?? null;
|
|
63
|
-
}
|
|
64
|
-
async get(sql, parameters) {
|
|
65
|
-
const result = await this.getOptional(sql, parameters);
|
|
66
|
-
if (!result) {
|
|
67
|
-
throw new Error('Result set is empty');
|
|
68
|
-
}
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
//# sourceMappingURL=OPSQLiteConnection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["BaseObserver","RowUpdateType","OPSQLiteConnection","constructor","options","DB","baseDB","updateHook","update","iterateListeners","cb","opType","operation","SQLITE_INSERT","SQLITE_DELETE","SQLITE_UPDATE","tablesUpdated","table","rowId","close","execute","query","params","res","insertId","rowsAffected","rows","_array","length","item","index","executeBatch","tuple","slice","forEach","p","push","result","getAll","sql","parameters","getOptional","get","Error"],"sourceRoot":"../../../src","sources":["db/OPSQLiteConnection.ts"],"mappings":";;AACA,SAASA,YAAY,EAAkCC,aAAa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-
|
|
3
|
-
import { BaseObserver } from '@powersync/common';
|
|
4
|
-
import { ANDROID_DATABASE_PATH, IOS_LIBRARY_PATH, open } from '@op-engineering/op-sqlite';
|
|
5
|
-
import Lock from 'async-lock';
|
|
6
|
-
import { OPSQLiteConnection } from "./OPSQLiteConnection.js";
|
|
7
|
-
import { NativeModules, Platform } from 'react-native';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Adapter for React Native Quick SQLite
|
|
11
|
-
*/
|
|
12
|
-
var LockType = /*#__PURE__*/function (LockType) {
|
|
13
|
-
LockType["READ"] = "read";
|
|
14
|
-
LockType["WRITE"] = "write";
|
|
15
|
-
return LockType;
|
|
16
|
-
}(LockType || {});
|
|
17
|
-
const READ_CONNECTIONS = 5;
|
|
18
|
-
export class OPSQLiteDBAdapter extends BaseObserver {
|
|
19
|
-
readQueue = [];
|
|
20
|
-
constructor(options) {
|
|
21
|
-
super();
|
|
22
|
-
this.options = options;
|
|
23
|
-
this.name = this.options.name;
|
|
24
|
-
this.locks = new Lock();
|
|
25
|
-
this.readConnections = null;
|
|
26
|
-
this.writeConnection = null;
|
|
27
|
-
this.initialized = this.init();
|
|
28
|
-
}
|
|
29
|
-
async init() {
|
|
30
|
-
const {
|
|
31
|
-
lockTimeoutMs,
|
|
32
|
-
journalMode,
|
|
33
|
-
journalSizeLimit,
|
|
34
|
-
synchronous,
|
|
35
|
-
encryptionKey
|
|
36
|
-
} = this.options.sqliteOptions;
|
|
37
|
-
const dbFilename = this.options.name;
|
|
38
|
-
this.writeConnection = await this.openConnection(dbFilename);
|
|
39
|
-
const statements = [`PRAGMA busy_timeout = ${lockTimeoutMs}`, `PRAGMA journal_mode = ${journalMode}`, `PRAGMA journal_size_limit = ${journalSizeLimit}`, `PRAGMA synchronous = ${synchronous}`];
|
|
40
|
-
for (const statement of statements) {
|
|
41
|
-
for (let tries = 0; tries < 30; tries++) {
|
|
42
|
-
try {
|
|
43
|
-
await this.writeConnection.execute(statement);
|
|
44
|
-
break;
|
|
45
|
-
} catch (e) {
|
|
46
|
-
if (e instanceof Error && e.message.includes('database is locked') && tries < 29) {
|
|
47
|
-
continue;
|
|
48
|
-
} else {
|
|
49
|
-
throw e;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Changes should only occur in the write connection
|
|
56
|
-
this.writeConnection.registerListener({
|
|
57
|
-
tablesUpdated: notification => this.iterateListeners(cb => cb.tablesUpdated?.(notification))
|
|
58
|
-
});
|
|
59
|
-
this.readConnections = [];
|
|
60
|
-
for (let i = 0; i < READ_CONNECTIONS; i++) {
|
|
61
|
-
// Workaround to create read-only connections
|
|
62
|
-
let dbName = './'.repeat(i + 1) + dbFilename;
|
|
63
|
-
const conn = await this.openConnection(dbName);
|
|
64
|
-
await conn.execute('PRAGMA query_only = true');
|
|
65
|
-
this.readConnections.push({
|
|
66
|
-
busy: false,
|
|
67
|
-
connection: conn
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
async openConnection(filenameOverride) {
|
|
72
|
-
const dbFilename = filenameOverride ?? this.options.name;
|
|
73
|
-
const DB = this.openDatabase(dbFilename, this.options.sqliteOptions.encryptionKey);
|
|
74
|
-
|
|
75
|
-
//Load extension for all connections
|
|
76
|
-
this.loadExtension(DB);
|
|
77
|
-
await DB.execute('SELECT powersync_init()');
|
|
78
|
-
return new OPSQLiteConnection({
|
|
79
|
-
baseDB: DB
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
getDbLocation(dbLocation) {
|
|
83
|
-
if (Platform.OS === 'ios') {
|
|
84
|
-
return dbLocation ?? IOS_LIBRARY_PATH;
|
|
85
|
-
} else {
|
|
86
|
-
return dbLocation ?? ANDROID_DATABASE_PATH;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
openDatabase(dbFilename, encryptionKey) {
|
|
90
|
-
//This is needed because an undefined/null dbLocation will cause the open function to fail
|
|
91
|
-
const location = this.getDbLocation(this.options.dbLocation);
|
|
92
|
-
//Simarlily if the encryption key is undefined/null when using SQLCipher it will cause the open function to fail
|
|
93
|
-
if (encryptionKey) {
|
|
94
|
-
return open({
|
|
95
|
-
name: dbFilename,
|
|
96
|
-
location: location,
|
|
97
|
-
encryptionKey: encryptionKey
|
|
98
|
-
});
|
|
99
|
-
} else {
|
|
100
|
-
return open({
|
|
101
|
-
name: dbFilename,
|
|
102
|
-
location: location
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
loadExtension(DB) {
|
|
107
|
-
if (Platform.OS === 'ios') {
|
|
108
|
-
const bundlePath = NativeModules.PowerSyncOpSqlite.getBundlePath();
|
|
109
|
-
const libPath = `${bundlePath}/Frameworks/powersync-sqlite-core.framework/powersync-sqlite-core`;
|
|
110
|
-
DB.loadExtension(libPath, 'sqlite3_powersync_init');
|
|
111
|
-
} else {
|
|
112
|
-
DB.loadExtension('libpowersync', 'sqlite3_powersync_init');
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
close() {
|
|
116
|
-
this.initialized.then(() => {
|
|
117
|
-
this.writeConnection.close();
|
|
118
|
-
this.readConnections.forEach(c => c.connection.close());
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
async readLock(fn, options) {
|
|
122
|
-
await this.initialized;
|
|
123
|
-
return new Promise(async (resolve, reject) => {
|
|
124
|
-
const execute = async () => {
|
|
125
|
-
// Find an available connection that is not busy
|
|
126
|
-
const availableConnection = this.readConnections.find(conn => !conn.busy);
|
|
127
|
-
|
|
128
|
-
// If we have an available connection, use it
|
|
129
|
-
if (availableConnection) {
|
|
130
|
-
availableConnection.busy = true;
|
|
131
|
-
try {
|
|
132
|
-
resolve(await fn(availableConnection.connection));
|
|
133
|
-
} catch (error) {
|
|
134
|
-
reject(error);
|
|
135
|
-
} finally {
|
|
136
|
-
availableConnection.busy = false;
|
|
137
|
-
// After query execution, process any queued tasks
|
|
138
|
-
this.processQueue();
|
|
139
|
-
}
|
|
140
|
-
} else {
|
|
141
|
-
// If no available connections, add to the queue
|
|
142
|
-
this.readQueue.push(execute);
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
execute();
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
async processQueue() {
|
|
149
|
-
if (this.readQueue.length > 0) {
|
|
150
|
-
const next = this.readQueue.shift();
|
|
151
|
-
if (next) {
|
|
152
|
-
next();
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
async writeLock(fn, options) {
|
|
157
|
-
await this.initialized;
|
|
158
|
-
return new Promise(async (resolve, reject) => {
|
|
159
|
-
try {
|
|
160
|
-
await this.locks.acquire(LockType.WRITE, async () => {
|
|
161
|
-
resolve(await fn(this.writeConnection));
|
|
162
|
-
}, {
|
|
163
|
-
timeout: options?.timeoutMs
|
|
164
|
-
});
|
|
165
|
-
} catch (ex) {
|
|
166
|
-
reject(ex);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
readTransaction(fn, options) {
|
|
171
|
-
return this.readLock(ctx => this.internalTransaction(ctx, fn));
|
|
172
|
-
}
|
|
173
|
-
writeTransaction(fn, options) {
|
|
174
|
-
return this.writeLock(ctx => this.internalTransaction(ctx, fn));
|
|
175
|
-
}
|
|
176
|
-
getAll(sql, parameters) {
|
|
177
|
-
return this.readLock(ctx => ctx.getAll(sql, parameters));
|
|
178
|
-
}
|
|
179
|
-
getOptional(sql, parameters) {
|
|
180
|
-
return this.readLock(ctx => ctx.getOptional(sql, parameters));
|
|
181
|
-
}
|
|
182
|
-
get(sql, parameters) {
|
|
183
|
-
return this.readLock(ctx => ctx.get(sql, parameters));
|
|
184
|
-
}
|
|
185
|
-
execute(query, params) {
|
|
186
|
-
return this.writeLock(ctx => ctx.execute(query, params));
|
|
187
|
-
}
|
|
188
|
-
async executeBatch(query, params = []) {
|
|
189
|
-
return this.writeLock(ctx => ctx.executeBatch(query, params));
|
|
190
|
-
}
|
|
191
|
-
async internalTransaction(connection, fn) {
|
|
192
|
-
let finalized = false;
|
|
193
|
-
const commit = async () => {
|
|
194
|
-
if (finalized) {
|
|
195
|
-
return {
|
|
196
|
-
rowsAffected: 0
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
finalized = true;
|
|
200
|
-
return connection.execute('COMMIT');
|
|
201
|
-
};
|
|
202
|
-
const rollback = async () => {
|
|
203
|
-
if (finalized) {
|
|
204
|
-
return {
|
|
205
|
-
rowsAffected: 0
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
finalized = true;
|
|
209
|
-
return connection.execute('ROLLBACK');
|
|
210
|
-
};
|
|
211
|
-
try {
|
|
212
|
-
await connection.execute('BEGIN');
|
|
213
|
-
const result = await fn({
|
|
214
|
-
execute: (query, params) => connection.execute(query, params),
|
|
215
|
-
get: (query, params) => connection.get(query, params),
|
|
216
|
-
getAll: (query, params) => connection.getAll(query, params),
|
|
217
|
-
getOptional: (query, params) => connection.getOptional(query, params),
|
|
218
|
-
commit,
|
|
219
|
-
rollback
|
|
220
|
-
});
|
|
221
|
-
await commit();
|
|
222
|
-
return result;
|
|
223
|
-
} catch (ex) {
|
|
224
|
-
await rollback();
|
|
225
|
-
throw ex;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
//# sourceMappingURL=OPSqliteAdapter.js.map
|