@capacitor-community/sqlite 5.0.7-2 → 5.0.8

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.
Files changed (33) hide show
  1. package/README.md +17 -2
  2. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +126 -3
  3. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +115 -1
  4. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +142 -80
  5. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +9 -9
  6. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsDelete.java +484 -0
  7. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsDrop.java +3 -3
  8. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLStatement.java +169 -0
  9. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +4 -4
  10. package/dist/esm/definitions.d.ts +117 -13
  11. package/dist/esm/definitions.js +103 -51
  12. package/dist/esm/definitions.js.map +1 -1
  13. package/dist/esm/web.d.ts +4 -0
  14. package/dist/esm/web.js +44 -0
  15. package/dist/esm/web.js.map +1 -1
  16. package/dist/plugin.cjs.js +147 -51
  17. package/dist/plugin.cjs.js.map +1 -1
  18. package/dist/plugin.js +147 -51
  19. package/dist/plugin.js.map +1 -1
  20. package/electron/dist/plugin.js +605 -181
  21. package/electron/dist/plugin.js.map +1 -1
  22. package/ios/Plugin/CapacitorSQLite.swift +123 -2
  23. package/ios/Plugin/CapacitorSQLitePlugin.m +4 -0
  24. package/ios/Plugin/CapacitorSQLitePlugin.swift +131 -1
  25. package/ios/Plugin/Database.swift +79 -2
  26. package/ios/Plugin/ImportExportJson/ImportFromJson.swift +13 -2
  27. package/ios/Plugin/Utils/UtilsDelete.swift +119 -117
  28. package/ios/Plugin/Utils/UtilsSQLCipher.swift +13 -5
  29. package/ios/Plugin/Utils/UtilsSQLStatement.swift +84 -84
  30. package/ios/Plugin/Utils/UtilsUpgrade.swift +3 -0
  31. package/package.json +5 -2
  32. package/src/definitions.ts +214 -57
  33. package/src/web.ts +48 -0
package/README.md CHANGED
@@ -18,7 +18,7 @@
18
18
  <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>
19
19
  <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>
20
20
  <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
21
- <a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-36-orange?style=flat-square" /></a>
21
+ <a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-37-orange?style=flat-square" /></a>
22
22
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
23
23
  </p>
24
24
 
@@ -75,7 +75,7 @@ const config: CapacitorConfig = {
75
75
  biometricTitle : "Biometric login for capacitor sqlite",
76
76
  biometricSubTitle : "Log in using your biometric"
77
77
  },
78
- electronIsEncryption: false,
78
+ electronIsEncryption: true,
79
79
  electronWindowsLocation: "C:\\ProgramData\\CapacitorDatabases",
80
80
  electronMacLocation: "/Volumes/Development_Lacie/Development/Databases",
81
81
  electronLinuxLocation: "Databases"
@@ -96,6 +96,12 @@ export default config;
96
96
  - [Datatypes In SQLite Version 3](https://www.sqlite.org/datatype3.html)
97
97
  - [IncrementalUpgradeDatabaseVersion](https://capacitorjs.com/docs/IncrementalUpgradeDatabaseVersion.md)
98
98
 
99
+
100
+ ## Tutorials Blog
101
+
102
+ - [JeepQ Capacitor Plugin Tutorials](https://jepiqueau.github.io/)
103
+
104
+
99
105
  ## Web Quirks
100
106
 
101
107
  The plugin follows the guidelines from the `Capacitor Team`,
@@ -176,6 +182,7 @@ npm install --save crypto-js
176
182
  npm install --save-dev @types/better-sqlite3
177
183
  npm install --save-dev @types/electron-json-storage
178
184
  npm install --save-dev @types/crypto-js
185
+ npm install --save-dev electron-builder@24.6.3
179
186
  ```
180
187
  - **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.
181
188
 
@@ -242,6 +249,10 @@ npm install --save-dev @types/crypto-js
242
249
  | isInConfigBiometricAuth | ✅ | ✅ | ❌ | ❌ | since 4.6.2-2
243
250
  | getFromLocalDiskToStore | ❌ | ❌ | ❌ | ✅ | since 4.6.3
244
251
  | saveToLocalDisk | ❌ | ❌ | ❌ | ✅ | since 4.6.3
252
+ | beginTransaction | ✅ | ✅ | ✅ | ✅ | since 5.0.7
253
+ | commitTransaction | ✅ | ✅ | ✅ | ✅ | since 5.0.7
254
+ | rollbackTransaction | ✅ | ✅ | ✅ | ✅ | since 5.0.7
255
+ | isTransactionActive | ✅ | ✅ | ✅ | ✅ | since 5.0.7
245
256
 
246
257
 
247
258
  ## Documentation & APIs
@@ -270,6 +281,9 @@ npm install --save-dev @types/crypto-js
270
281
 
271
282
  - [Electron Better SQLite3](https://github.com/capacitor-community/sqlite/blob/master/docs/ElectronBetterSQLite3.md)
272
283
 
284
+ - [Enable minified build on Android](https://github.com/capacitor-community/sqlite/blob/master/docs/AndroidMinify.md)
285
+
286
+
273
287
  ## Applications demonstrating the use of the plugin and related documentation
274
288
 
275
289
  ### Ionic/Angular
@@ -374,6 +388,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
374
388
  <a href="https://github.com/pranav-singhal" title="pranav-singhal"><img src="https://github.com/pranav-singhal.png?size=100" width="50" height="50" /></a>
375
389
  <a href="https://github.com/beligatclement" title="beligatclement"><img src="https://github.com/beligatclement.png?size=100" width="50" height="50" /></a>
376
390
  <a href="https://github.com/cosentino" title="cosentino"><img src="https://avatars.githubusercontent.com/u/376903?s=48&v=4" width="50" height="50" /></a>
391
+ <a href="https://github.com/Guiqft" title="cosentino"><img src="https://avatars.githubusercontent.com/u/9392803?v=4" width="50" height="50" /></a>
377
392
  </p>
378
393
 
379
394
 
@@ -451,6 +451,128 @@ public class CapacitorSQLite {
451
451
  throw new Exception(msg);
452
452
  }
453
453
  }
454
+ /**
455
+ * BeginTransaction
456
+ *
457
+ * @param dbName Database name
458
+ * @return JSObject changes
459
+ * @throws Exception message
460
+ */
461
+ public JSObject beginTransaction(String dbName) throws Exception {
462
+ JSObject retObj = new JSObject();
463
+ dbName = getDatabaseName(dbName);
464
+ String connName = "RW_" + dbName;
465
+ Database db = dbDict.get(connName);
466
+ if (db != null) {
467
+ if (!db.isNCDB() && db.isOpen()) {
468
+ try {
469
+ Integer res = db.beginTransaction();
470
+ retObj.put("changes", res);
471
+ return retObj;
472
+ } catch (Exception e) {
473
+ throw new Exception(e.getMessage());
474
+ }
475
+ } else {
476
+ String msg = "database " + dbName + " not opened";
477
+ throw new Exception(msg);
478
+ }
479
+ } else {
480
+ String msg = "No available connection for database " + dbName;
481
+ throw new Exception(msg);
482
+ }
483
+ }
484
+
485
+ /**
486
+ * CommitTransaction
487
+ *
488
+ * @param dbName Database name
489
+ * @return JSObject changes
490
+ * @throws Exception message
491
+ */
492
+ public JSObject commitTransaction(String dbName) throws Exception {
493
+ JSObject retObj = new JSObject();
494
+ dbName = getDatabaseName(dbName);
495
+ String connName = "RW_" + dbName;
496
+ Database db = dbDict.get(connName);
497
+ if (db != null) {
498
+ if (!db.isNCDB() && db.isOpen()) {
499
+ try {
500
+ Integer res = db.commitTransaction();
501
+ retObj.put("changes", res);
502
+ return retObj;
503
+ } catch (Exception e) {
504
+ throw new Exception(e.getMessage());
505
+ }
506
+ } else {
507
+ String msg = "database " + dbName + " not opened";
508
+ throw new Exception(msg);
509
+ }
510
+ } else {
511
+ String msg = "No available connection for database " + dbName;
512
+ throw new Exception(msg);
513
+ }
514
+ }
515
+
516
+ /**
517
+ * Rollback Transaction
518
+ *
519
+ * @param dbName Database name
520
+ * @return JSObject changes
521
+ * @throws Exception message
522
+ */
523
+ public JSObject rollbackTransaction(String dbName) throws Exception {
524
+ JSObject retObj = new JSObject();
525
+ dbName = getDatabaseName(dbName);
526
+ String connName = "RW_" + dbName;
527
+ Database db = dbDict.get(connName);
528
+ if (db != null) {
529
+ if (!db.isNCDB() && db.isOpen()) {
530
+ try {
531
+ Integer res = db.rollbackTransaction();
532
+ retObj.put("changes", res);
533
+ return retObj;
534
+ } catch (Exception e) {
535
+ throw new Exception(e.getMessage());
536
+ }
537
+ } else {
538
+ String msg = "database " + dbName + " not opened";
539
+ throw new Exception(msg);
540
+ }
541
+ } else {
542
+ String msg = "No available connection for database " + dbName;
543
+ throw new Exception(msg);
544
+ }
545
+ }
546
+
547
+ /**
548
+ * IsTransactionActive
549
+ *
550
+ * @param dbName database name
551
+ * @return Boolean
552
+ * @throws Exception message
553
+ */
554
+ public Boolean isTransactionActive(String dbName) throws Exception {
555
+ dbName = getDatabaseName(dbName);
556
+ String connName = "RW_" + dbName;
557
+ Database db = dbDict.get(connName);
558
+ if (db != null) {
559
+ if (!db.isNCDB() && db.isOpen()) {
560
+ try {
561
+ boolean res = db.isAvailTrans();
562
+ return res;
563
+ } catch (Exception e) {
564
+ throw new Exception(e.getMessage());
565
+ }
566
+
567
+ } else {
568
+ String msg = "database " + dbName + " not opened";
569
+ throw new Exception(msg);
570
+ }
571
+ } else {
572
+ String msg = "No available connection for database " + dbName;
573
+ throw new Exception(msg);
574
+ }
575
+ }
454
576
 
455
577
  /**
456
578
  * GetUrl
@@ -846,7 +968,7 @@ public class CapacitorSQLite {
846
968
  }
847
969
  } else {
848
970
  try {
849
- res = db.runSQL(statement, null, transaction, returnMode);
971
+ res = db.runSQL(statement, new ArrayList<>(), transaction, returnMode);
850
972
  return res;
851
973
  } catch (Exception e) {
852
974
  throw new Exception(e.getMessage());
@@ -1147,7 +1269,8 @@ public class CapacitorSQLite {
1147
1269
  }
1148
1270
  }
1149
1271
 
1150
- public JSObject exportToJson(String dbName, String expMode, Boolean readonly) throws Exception {
1272
+ public JSObject exportToJson(String dbName, String expMode,
1273
+ Boolean readonly, Boolean encrypted) throws Exception {
1151
1274
  dbName = getDatabaseName(dbName);
1152
1275
  String connName = readonly ? "RO_" + dbName : "RW_" + dbName;
1153
1276
  Database db = dbDict.get(connName);
@@ -1157,7 +1280,7 @@ public class CapacitorSQLite {
1157
1280
  String msg = "ExportToJson: db not opened";
1158
1281
  throw new Exception(msg);
1159
1282
  }
1160
- JSObject ret = db.exportToJson(expMode);
1283
+ JSObject ret = db.exportToJson(expMode, encrypted);
1161
1284
  if (ret.length() == 0) {
1162
1285
  String msg = "ExportToJson: : return Object is empty " + "No data to synchronize";
1163
1286
  throw new Exception(msg);
@@ -369,7 +369,119 @@ public class CapacitorSQLitePlugin extends Plugin {
369
369
  rHandler.retResult(call, null, loadMessage);
370
370
  }
371
371
  }
372
+ /**
373
+ * BeginTransaction Method
374
+ * Begin a Database Transaction
375
+ *
376
+ * @param call PluginCall
377
+ */
378
+ @PluginMethod
379
+ public void beginTransaction(PluginCall call) {
380
+ JSObject retRes = new JSObject();
381
+ retRes.put("changes", Integer.valueOf(-1));
382
+ if (!call.getData().has("database")) {
383
+ String msg = "BeginTransaction: Must provide a database name";
384
+ rHandler.retChanges(call, retRes, msg);
385
+ return;
386
+ }
387
+ String dbName = call.getString("database");
388
+
389
+ if (implementation != null) {
390
+ try {
391
+ JSObject res = implementation.beginTransaction(dbName);
392
+ rHandler.retChanges(call, res, null);
393
+ } catch (Exception e) {
394
+ String msg = "BeginTransaction: " + e.getMessage();
395
+ rHandler.retChanges(call, retRes, msg);
396
+ }
397
+ } else {
398
+ rHandler.retChanges(call, retRes, loadMessage);
399
+ }
400
+ }
401
+ /**
402
+ * CommitTransaction Method
403
+ * Commit a Database Transaction
404
+ *
405
+ * @param call PluginCall
406
+ */
407
+ @PluginMethod
408
+ public void commitTransaction(PluginCall call) {
409
+ JSObject retRes = new JSObject();
410
+ retRes.put("changes", Integer.valueOf(-1));
411
+ if (!call.getData().has("database")) {
412
+ String msg = "CommitTransaction: Must provide a database name";
413
+ rHandler.retChanges(call, retRes, msg);
414
+ return;
415
+ }
416
+ String dbName = call.getString("database");
417
+
418
+ if (implementation != null) {
419
+ try {
420
+ JSObject res = implementation.commitTransaction(dbName);
421
+ rHandler.retChanges(call, res, null);
422
+ } catch (Exception e) {
423
+ String msg = "CommitTransaction: " + e.getMessage();
424
+ rHandler.retChanges(call, retRes, msg);
425
+ }
426
+ } else {
427
+ rHandler.retChanges(call, retRes, loadMessage);
428
+ }
429
+ }
372
430
 
431
+ /**
432
+ * RollbackTransaction Method
433
+ * Rollbact a Database Transaction
434
+ *
435
+ * @param call PluginCall
436
+ */
437
+ @PluginMethod
438
+ public void rollbackTransaction(PluginCall call) {
439
+ JSObject retRes = new JSObject();
440
+ retRes.put("changes", Integer.valueOf(-1));
441
+ if (!call.getData().has("database")) {
442
+ String msg = "RollbackTransaction: Must provide a database name";
443
+ rHandler.retChanges(call, retRes, msg);
444
+ return;
445
+ }
446
+ String dbName = call.getString("database");
447
+
448
+ if (implementation != null) {
449
+ try {
450
+ JSObject res = implementation.rollbackTransaction(dbName);
451
+ rHandler.retChanges(call, res, null);
452
+ } catch (Exception e) {
453
+ String msg = "RollbackTransaction: " + e.getMessage();
454
+ rHandler.retChanges(call, retRes, msg);
455
+ }
456
+ } else {
457
+ rHandler.retChanges(call, retRes, loadMessage);
458
+ }
459
+ }
460
+ /**
461
+ * IsTransactionActive Method
462
+ * Check if a Database Transaction is Active
463
+ *
464
+ * @param call PluginCall
465
+ */
466
+ @PluginMethod
467
+ public void isTransactionActive(PluginCall call) {
468
+ if (!call.getData().has("database")) {
469
+ rHandler.retResult(call, null, "Must provide a database name");
470
+ return;
471
+ }
472
+ String dbName = call.getString("database");
473
+ if (implementation != null) {
474
+ try {
475
+ Boolean res = implementation.isTransactionActive(dbName);
476
+ rHandler.retResult(call, res, null);
477
+ } catch (Exception e) {
478
+ String msg = "IsTransactionActive: " + e.getMessage();
479
+ rHandler.retResult(call, null, msg);
480
+ }
481
+ } else {
482
+ rHandler.retResult(call, null, loadMessage);
483
+ }
484
+ }
373
485
  /**
374
486
  * GetUrl Method
375
487
  * Get a database Url
@@ -1336,10 +1448,12 @@ public class CapacitorSQLitePlugin extends Plugin {
1336
1448
  return;
1337
1449
  }
1338
1450
  Boolean readOnly = call.getBoolean("readonly", false);
1451
+ Boolean encrypted = call.getBoolean("encrypted", false);
1339
1452
 
1340
1453
  if (implementation != null) {
1341
1454
  try {
1342
- JSObject res = implementation.exportToJson(dbName, expMode, readOnly);
1455
+ JSObject res = implementation.exportToJson(dbName, expMode,
1456
+ readOnly, encrypted);
1343
1457
  rHandler.retJSObject(call, res, null);
1344
1458
  } catch (Exception e) {
1345
1459
  String msg = "ExportToJson: " + e.getMessage();