@capacitor-community/sqlite 4.6.0 → 4.6.1-2
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 +16 -9
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +21 -20
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +1 -1
- package/electron/dist/plugin.js +49 -18
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +6 -6
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
</p>
|
|
10
10
|
<br>
|
|
11
11
|
<p align="center">
|
|
12
|
-
<img src="https://img.shields.io/maintenance/yes/
|
|
12
|
+
<img src="https://img.shields.io/maintenance/yes/2023?style=flat-square" />
|
|
13
13
|
<a href="https://github.com/capacitor-community/sqlite/actions?query=workflow%3A%22CI%22"><img src="https://img.shields.io/github/workflow/status/capacitor-community/sqlite/CI?style=flat-square" /></a>
|
|
14
14
|
<a href="https://www.npmjs.com/package/@capacitor-community/sqlite"><img src="https://img.shields.io/npm/l/@capacitor-community/sqlite?style=flat-square" /></a>
|
|
15
15
|
<br>
|
|
16
16
|
<a href="https://www.npmjs.com/package/@capacitor-community/sqlite"><img src="https://img.shields.io/npm/dw/@capacitor-community/sqlite?style=flat-square" /></a>
|
|
17
17
|
<a href="https://www.npmjs.com/package/@capacitor-community/sqlite"><img src="https://img.shields.io/npm/v/@capacitor-community/sqlite?style=flat-square" /></a>
|
|
18
18
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
19
|
-
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-
|
|
19
|
+
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-28-orange?style=flat-square" /></a>
|
|
20
20
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
21
21
|
</p>
|
|
22
22
|
|
|
@@ -35,7 +35,7 @@ npx cap sync
|
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
```
|
|
38
|
-
yarn
|
|
38
|
+
yarn add @capacitor-community/sqlite
|
|
39
39
|
npx cap sync
|
|
40
40
|
```
|
|
41
41
|
|
|
@@ -92,7 +92,7 @@ See [#301](https://github.com/capacitor-community/sqlite/issues/301) and [SO que
|
|
|
92
92
|
cd electron
|
|
93
93
|
npm install --save sqlite3
|
|
94
94
|
npm install --save jszip
|
|
95
|
-
npm install --save node-fetch
|
|
95
|
+
npm install --save node-fetch@2.6.7
|
|
96
96
|
npm install --save-dev @types/sqlite3
|
|
97
97
|
```
|
|
98
98
|
- **Important**: `node-fetch` version must be `<=2.6.7`; otherwise [you'll get an error](https://github.com/capacitor-community/sqlite/issues/349 "you'll get an error ERR_REQUIRE_ESM") running the app.
|
|
@@ -189,6 +189,10 @@ npm install --save-dev @types/sqlite3
|
|
|
189
189
|
|
|
190
190
|
- [angular-sqlite-synchronize-app](https://github.com/jepiqueau/angular-sqlite-synchronize-app)
|
|
191
191
|
|
|
192
|
+
### Ionic/Angular TypeORM app
|
|
193
|
+
|
|
194
|
+
- [ionic-sqlite-typeorm-app](https://github.com/jepiqueau/ionic-sqlite-typeorm-app)
|
|
195
|
+
|
|
192
196
|
### Ionic/React
|
|
193
197
|
|
|
194
198
|
- [Ionic/React Usage Documentation](https://github.com/capacitor-community/sqlite/blob/master/docs/Ionic-React-Usage.md)
|
|
@@ -213,14 +217,14 @@ npm install --save-dev @types/sqlite3
|
|
|
213
217
|
|
|
214
218
|
- [vue-vite-sqlite-app](https://github.com/jepiqueau/vuevite-app)
|
|
215
219
|
|
|
216
|
-
### SolidJS+Vite
|
|
217
|
-
|
|
218
|
-
- [solidjs-vite-sqlite-app](https://github.com/jepiqueau/capacitor-solid-sqlite)
|
|
219
|
-
|
|
220
220
|
### Vue TypeORM app
|
|
221
221
|
|
|
222
222
|
- [vue-typeorm-app](https://github.com/jepiqueau/vue-typeorm-app)
|
|
223
223
|
|
|
224
|
+
### SolidJS+Vite
|
|
225
|
+
|
|
226
|
+
- [solidjs-vite-sqlite-app](https://github.com/jepiqueau/capacitor-solid-sqlite)
|
|
227
|
+
|
|
224
228
|
|
|
225
229
|
## Dependencies
|
|
226
230
|
|
|
@@ -262,7 +266,10 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|
|
262
266
|
<a href="https://github.com/aeinn" title="aeinn"><img src="https://github.com/aeinn.png?size=100" width="50" height="50" /></a>
|
|
263
267
|
<a href="https://github.com/jonz94" title="jonz94"><img src="https://github.com/jonz94.png?size=100" width="50" height="50" /></a>
|
|
264
268
|
<a href="https://github.com/oscarfonts" title="oscarfonts"><img src="https://github.com/oscarfonts.png?size=100" width="50" height="50" /></a>
|
|
265
|
-
|
|
269
|
+
<a href="https://github.com/Sirs0ri" title="Sirs0ri"><img src="https://github.com/Sirs0ri.png?size=100" width="50" height="50" /></a></p>
|
|
270
|
+
<a href="https://github.com/TheNovemberRain" title="TheNovemberRain"><img src="https://github.com/TheNovemberRain.png?size=100" width="50" height="50" /></a></p>
|
|
271
|
+
<a href="https://github.com/fizdalf" title="fizdalf"><img src="https://github.com/fizdalf.png?size=100" width="50" height="50" /></a></p>
|
|
272
|
+
|
|
266
273
|
|
|
267
274
|
<!-- markdownlint-enable -->
|
|
268
275
|
<!-- prettier-ignore-end -->
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java
CHANGED
|
@@ -1019,27 +1019,28 @@ public class CapacitorSQLite {
|
|
|
1019
1019
|
public Dictionary<Integer, JSONObject> addUpgradeStatement(JSArray upgrade) throws Exception {
|
|
1020
1020
|
Dictionary<Integer, JSONObject> upgDict = new Hashtable<>();
|
|
1021
1021
|
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1022
|
+
for (int i = 0; i < upgrade.length(); i++) {
|
|
1023
|
+
JSONObject upgObj = null;
|
|
1024
|
+
try {
|
|
1025
|
+
upgObj = (JSONObject) upgrade.get(i);
|
|
1026
|
+
if (upgObj == null || !upgObj.has("toVersion") || !upgObj.has("statements")) {
|
|
1027
|
+
String msg = "Must provide an upgrade statement";
|
|
1028
|
+
msg += " {toVersion,statement}";
|
|
1029
|
+
throw new Exception(msg);
|
|
1030
|
+
}
|
|
1031
|
+
} catch (Exception e) {
|
|
1032
|
+
String msg = "Must provide an upgrade statement " + e.getMessage();
|
|
1033
|
+
throw new Exception(msg);
|
|
1034
|
+
}
|
|
1035
|
+
try {
|
|
1036
|
+
int toVersion = upgObj.getInt("toVersion");
|
|
1037
|
+
upgDict.put(toVersion, upgObj);
|
|
1038
|
+
} catch (Exception e) {
|
|
1039
|
+
String msg = "Must provide toVersion as Integer" + e.getMessage();
|
|
1040
|
+
throw new Exception(msg);
|
|
1041
|
+
}
|
|
1042
1042
|
}
|
|
1043
|
+
return upgDict;
|
|
1043
1044
|
}
|
|
1044
1045
|
|
|
1045
1046
|
public Boolean isJsonValid(String parsingData) throws Exception {
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java
CHANGED
|
@@ -171,7 +171,7 @@ public class Database {
|
|
|
171
171
|
if (!isNCDB() && !this._readOnly) {
|
|
172
172
|
_db = SQLiteDatabase.openOrCreateDatabase(_file, password, null);
|
|
173
173
|
} else {
|
|
174
|
-
_db = SQLiteDatabase.openDatabase(String.valueOf(_file),
|
|
174
|
+
_db = SQLiteDatabase.openDatabase(String.valueOf(_file), password, null, SQLiteDatabase.OPEN_READONLY);
|
|
175
175
|
}
|
|
176
176
|
if (_db != null) {
|
|
177
177
|
if (_db.isOpen()) {
|
package/electron/dist/plugin.js
CHANGED
|
@@ -3012,17 +3012,40 @@ class UtilsFile {
|
|
|
3012
3012
|
* @param filePath
|
|
3013
3013
|
*/
|
|
3014
3014
|
async deleteFilePath(filePath) {
|
|
3015
|
+
let unlinkRetries = 50000;
|
|
3016
|
+
/**
|
|
3017
|
+
* On windows, the file lock behaves unpredictable. Often it claims a databsae file is locked / busy, although
|
|
3018
|
+
* the file stream is already closed.
|
|
3019
|
+
* Even though we already checked the status with the `waitForFilePathLock()` method previously.
|
|
3020
|
+
*
|
|
3021
|
+
* The only way to handle this reliably is to retry deletion until it works.
|
|
3022
|
+
*/
|
|
3023
|
+
const deleteFile = async () => {
|
|
3024
|
+
try {
|
|
3025
|
+
await promises_1.unlink(filePath);
|
|
3026
|
+
}
|
|
3027
|
+
catch (err) {
|
|
3028
|
+
unlinkRetries--;
|
|
3029
|
+
if (unlinkRetries > 0) {
|
|
3030
|
+
await deleteFile();
|
|
3031
|
+
}
|
|
3032
|
+
else {
|
|
3033
|
+
throw err;
|
|
3034
|
+
}
|
|
3035
|
+
}
|
|
3036
|
+
};
|
|
3015
3037
|
if (filePath.length !== 0) {
|
|
3016
3038
|
// check if path exists
|
|
3017
3039
|
const isPath = this.isPathExists(filePath);
|
|
3018
3040
|
if (isPath) {
|
|
3019
3041
|
try {
|
|
3020
3042
|
await this.waitForFilePathLock(filePath);
|
|
3021
|
-
|
|
3043
|
+
// actually delete the file
|
|
3044
|
+
await deleteFile();
|
|
3022
3045
|
return Promise.resolve();
|
|
3023
3046
|
}
|
|
3024
3047
|
catch (err) {
|
|
3025
|
-
return Promise.reject(
|
|
3048
|
+
return Promise.reject(`DeleteFilePath: ${err}`);
|
|
3026
3049
|
}
|
|
3027
3050
|
}
|
|
3028
3051
|
else {
|
|
@@ -3259,6 +3282,7 @@ class UtilsUpgrade {
|
|
|
3259
3282
|
async onUpgrade(mDB, vUpgDict, curVersion, targetVersion) {
|
|
3260
3283
|
let changes;
|
|
3261
3284
|
const sortedKeys = new Int32Array(Object.keys(vUpgDict).map(item => parseInt(item))).sort();
|
|
3285
|
+
console.log(`@@@ sortedKeys: ${sortedKeys}`);
|
|
3262
3286
|
for (const versionKey of sortedKeys) {
|
|
3263
3287
|
if (versionKey > curVersion && versionKey <= targetVersion) {
|
|
3264
3288
|
const statements = vUpgDict[versionKey].statements;
|
|
@@ -3276,6 +3300,7 @@ class UtilsUpgrade {
|
|
|
3276
3300
|
changes = (await this.sqliteUtil.dbChanges(mDB)) - initChanges;
|
|
3277
3301
|
}
|
|
3278
3302
|
catch (err) {
|
|
3303
|
+
console.log(`@@@@ onUpgrade: ${err}`);
|
|
3279
3304
|
return Promise.reject(`onUpgrade: ${err}`);
|
|
3280
3305
|
}
|
|
3281
3306
|
}
|
|
@@ -3291,6 +3316,7 @@ class UtilsUpgrade {
|
|
|
3291
3316
|
try {
|
|
3292
3317
|
await this.sqliteUtil.beginTransaction(mDB, true);
|
|
3293
3318
|
for (const statement of statements) {
|
|
3319
|
+
console.log(`@@@ statement: ${statement}`);
|
|
3294
3320
|
await this.sqliteUtil.execute(mDB, statement, false);
|
|
3295
3321
|
}
|
|
3296
3322
|
await this.sqliteUtil.commitTransaction(mDB, true);
|
|
@@ -3298,6 +3324,7 @@ class UtilsUpgrade {
|
|
|
3298
3324
|
}
|
|
3299
3325
|
catch (err) {
|
|
3300
3326
|
await this.sqliteUtil.rollbackTransaction(mDB, true);
|
|
3327
|
+
console.log(`@@@ ExecuteStatementProcess: ${err}`);
|
|
3301
3328
|
return Promise.reject(`ExecuteStatementProcess: ${err}`);
|
|
3302
3329
|
}
|
|
3303
3330
|
}
|
|
@@ -3381,6 +3408,8 @@ class Database {
|
|
|
3381
3408
|
this._isDbOpen = true;
|
|
3382
3409
|
if (!this.readonly) {
|
|
3383
3410
|
const curVersion = await this.sqliteUtil.getVersion(this.database);
|
|
3411
|
+
console.log(`@@@@ this.readonly: ${this.readonly}`);
|
|
3412
|
+
console.log(`@@@@ this.version: ${this.version} curVersion: ${curVersion}`);
|
|
3384
3413
|
if (this.version > curVersion &&
|
|
3385
3414
|
Object.keys(this.upgradeVersionDict).length > 0) {
|
|
3386
3415
|
try {
|
|
@@ -4325,23 +4354,25 @@ class CapacitorSQLite {
|
|
|
4325
4354
|
async addUpgradeStatement(options) {
|
|
4326
4355
|
const dbName = this.getOptionValue(options, 'database');
|
|
4327
4356
|
const upgrades = this.getOptionValue(options, 'upgrade');
|
|
4328
|
-
const
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4357
|
+
for (const upgrade of upgrades) {
|
|
4358
|
+
const versionUpgradeKeys = Object.keys(upgrade);
|
|
4359
|
+
if (!versionUpgradeKeys.includes('toVersion') ||
|
|
4360
|
+
!versionUpgradeKeys.includes('statements')) {
|
|
4361
|
+
throw new Error('Must provide an upgrade capSQLiteVersionUpgrade Object');
|
|
4362
|
+
}
|
|
4363
|
+
if (typeof upgrade.toVersion != 'number') {
|
|
4364
|
+
throw new Error('upgrade.toVersion must be a number');
|
|
4365
|
+
}
|
|
4366
|
+
if (this.versionUpgrades[dbName]) {
|
|
4367
|
+
this.versionUpgrades[dbName][upgrade.toVersion] = upgrade;
|
|
4368
|
+
}
|
|
4369
|
+
else {
|
|
4370
|
+
const upgradeVersionDict = {};
|
|
4371
|
+
upgradeVersionDict[upgrade.toVersion] = upgrade;
|
|
4372
|
+
this.versionUpgrades[dbName] = upgradeVersionDict;
|
|
4373
|
+
}
|
|
4344
4374
|
}
|
|
4375
|
+
console.log(`this.versionUpgrades: ${JSON.stringify(this.versionUpgrades)}`);
|
|
4345
4376
|
return;
|
|
4346
4377
|
}
|
|
4347
4378
|
async copyFromAssets(options) {
|