@capacitor-community/sqlite 3.4.3-1 → 3.4.3

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 (30) hide show
  1. package/README.md +55 -21
  2. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +41 -2
  3. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +26 -0
  4. package/android/src/main/java/com/getcapacitor/community/database/sqlite/NotificationCenter.java +1 -1
  5. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +220 -7
  6. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ExportToJson.java +100 -3
  7. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +37 -34
  8. package/dist/esm/definitions.d.ts +18 -4
  9. package/dist/esm/definitions.js +9 -17
  10. package/dist/esm/definitions.js.map +1 -1
  11. package/dist/esm/web.d.ts +2 -1
  12. package/dist/esm/web.js +11 -0
  13. package/dist/esm/web.js.map +1 -1
  14. package/dist/plugin.cjs.js +22 -19
  15. package/dist/plugin.cjs.js.map +1 -1
  16. package/dist/plugin.js +1035 -1032
  17. package/dist/plugin.js.map +1 -1
  18. package/electron/dist/plugin.js +662 -335
  19. package/electron/dist/plugin.js.map +1 -1
  20. package/ios/Plugin/CapacitorSQLite.swift +34 -1
  21. package/ios/Plugin/CapacitorSQLitePlugin.m +1 -0
  22. package/ios/Plugin/CapacitorSQLitePlugin.swift +25 -0
  23. package/ios/Plugin/Database.swift +29 -1
  24. package/ios/Plugin/Extensions/String.swift +8 -0
  25. package/ios/Plugin/ImportExportJson/ExportToJson.swift +154 -25
  26. package/ios/Plugin/ImportExportJson/ImportFromJson.swift +53 -27
  27. package/ios/Plugin/Utils/UtilsDrop.swift +2 -2
  28. package/ios/Plugin/Utils/UtilsSQLCipher.swift +277 -8
  29. package/ios/Plugin/Utils/UtilsUpgrade.swift +0 -1
  30. package/package.json +2 -2
package/README.md CHANGED
@@ -16,7 +16,7 @@
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-16-orange?style=flat-square" /></a>
19
+ <a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-17-orange?style=flat-square" /></a>
20
20
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
21
21
  </p>
22
22
 
@@ -28,6 +28,38 @@
28
28
 
29
29
  ## CAPACITOR 3 (Master)
30
30
 
31
+ 🚨 Release 3.4.3-3 all platforms ->> 🚨
32
+
33
+ The main change is related to the delete table's rows when a synchronization table exists as well as a last_mofidied table's column, allowing for database synchronization of the local database with a remote server database.
34
+
35
+ - All existing triggers to YOUR_TABLE_NAME_trigger_last_modified must be modified as follows
36
+ ```
37
+ CREATE TRIGGER YOUR_TABLE_NAME_trigger_last_modified
38
+ AFTER UPDATE ON YOUR_TABLE_NAME
39
+ FOR EACH ROW WHEN NEW.last_modified < OLD.last_modified
40
+ BEGIN
41
+ UPDATE YOUR_TABLE_NAME SET last_modified= (strftime('%s', 'now')) WHERE id=OLD.id;
42
+ END;
43
+ ```
44
+ - an new column `sql_deleted` must be added to each of your tables as
45
+ ```
46
+ sql_deleted BOOLEAN DEFAULT 0 CHECK (sql_deleted IN (0, 1))
47
+ ```
48
+ This column will be autommatically set to 1 when you will use a `DELETE FROM ...` sql statement in the `execute`, `run` or `executeSet` methods.
49
+
50
+ - In the JSON object that you provide to `importFromJson`, all the deleted rows in your remote server database's tables must have the `sql_deleted` column set to 1. This will indicate to the import process to physically delete the corresponding rows in your local database. All the others rows must have the `sql_deleted` column set to 0.
51
+
52
+ - In the JSON object outputs by the `exportToJson`, all the deleted rows in your local database have got the `sql_deleted` column set to 1 to help in your synchronization management process with the remote server database. A system `last_exported_date` is automatically saved in the synchronization table at the start of the export process flow.
53
+
54
+ - On successfull completion of your synchronization management process with the remote server database, you must
55
+ - Set a new synchronization date (as `(new Date()).toISOString()`) with the `setSyncDate` method.
56
+ - Execute the `deleteExportedRows` method which physically deletes all table's rows having 1 as value for the `sql_deleted` column prior to the `last_exported_date` in your local database.
57
+
58
+ An example of using this new feature is given in [solidjs-vite-sqlite-app](https://github.com/jepiqueau/capacitor-solid-sqlite). It has been used to test the validity of the implementation.
59
+
60
+
61
+ 🚨 Release 3.4.3-3 <<- 🚨
62
+
31
63
  🚨 Release 3.4.2-4 ->> 🚨
32
64
  !!!! DO NOT USE IT !!!!
33
65
  🚨 Release 3.4.2-4 <<- 🚨
@@ -297,6 +329,7 @@ No configuration required for this plugin
297
329
  | deleteDatabase | ✅ | ✅ | ✅ | ✅ |
298
330
  | importFromJson | ✅ | ✅ | ✅ | ✅ |
299
331
  | exportToJson | ✅ | ✅ | ✅ | ✅ |
332
+ | deleteExportedRows | ✅ | ✅ | ✅ | ✅ | NEW in 3.4.3-2
300
333
  | createSyncTable | ✅ | ✅ | ✅ | ✅ |
301
334
  | setSyncDate | ✅ | ✅ | ✅ | ✅ |
302
335
  | getSyncDate | ✅ | ✅ | ✅ | ✅ |
@@ -367,6 +400,8 @@ No configuration required for this plugin
367
400
 
368
401
  - [angular-sqlite-app-starter](https://github.com/jepiqueau/angular-sqlite-app-starter)
369
402
 
403
+ - [angular-sqlite-synchronize-app](https://github.com/jepiqueau/angular-sqlite-synchronize-app)
404
+
370
405
  ### Ionic/React
371
406
 
372
407
  - [react-sqlite-app-starter](https://github.com/jepiqueau/react-sqlite-app-starter)
@@ -412,26 +447,25 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
412
447
  <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
413
448
  <!-- prettier-ignore-start -->
414
449
  <!-- markdownlint-disable -->
415
- <table>
416
- <tr>
417
- <td align="center"><a href="https://github.com/jepiqueau"><img src="https://avatars3.githubusercontent.com/u/16580653?v=4" width="100px;" alt=""/><br /><sub><b>Jean Pierre Quéau</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=jepiqueau" title="Code">💻</a></td>
418
- <td align="center"><a href="https://github.com/paulantoine2"><img src="https://avatars0.githubusercontent.com/u/22882943?s=64&v=4" width="100px;" alt=""/><br /><sub><b>Paul Antoine</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=paulantoine2" title="Code">💻</a></td>
419
- <td align="center"><a href="https://github.com/karyfars"><img src="https://avatars2.githubusercontent.com/u/303016?s=60&u=1ce232ae3c22eac7b0b4778e46fe079939c39b40&v=4" width="100px;" alt=""/><br /><sub><b>Karyfars</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=karyfars" title="Code">💻</a></td>
420
- <td align="center"><a href="https://github.com/chriswep"><img src="https://avatars2.githubusercontent.com/u/1055809?s=400&u=e555940f143da8be255743028d6838cb5c020b44&v=4" width="100px;" alt=""/><br /><sub><b>Chriswep</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=chriswep" title="Documentation">📖</a></td>
421
- <td align="center"><a href="https://github.com/nirajhinge"><img src="https://avatars.githubusercontent.com/u/54309996?v=4" width="100px;" alt=""/><br /><sub><b>Nirajhinge</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=nirajhinge" title="Code">💻</a></td>
422
- <td align="center"><a href="https://github.com/digaus"><img src="https://avatars.githubusercontent.com/u/15358538?v=4" width="100px;" alt=""/><br /><sub><b>Dirk Gausmann</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=digaus" title="Code">💻</a></td>
423
- <td align="center"><a href="https://github.com/IT-MikeS"><img src="https://avatars.githubusercontent.com/u/20338451?v=4" width="100px;" alt=""/><br /><sub><b>Mike Summerfeldt</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=IT-MikeS" title="Code">💻</a></td>
424
- <td align="center"><a href="https://github.com/peakcool"><img src="https://avatars.githubusercontent.com/u/14804014?v=4" width="100px;" alt=""/><br /><sub><b>Peakcool</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=peakcool" title="Code">💻</a></td>
425
- <td align="center"><a href="https://github.com/gion-andri"><img src="https://avatars.githubusercontent.com/u/540998?v=4" width="100px;" alt=""/><br /><sub><b>Gion-Andri Cantieni</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=gion-andri" title="Documentation">📖</a></td>
426
- <td align="center"><a href="https://github.com/robingenz"><img src="https://avatars.githubusercontent.com/u/13857929?v=4" width="100px;" alt=""/><br /><sub><b>Robin Genz</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=robingenz" title="Documentation">📖</a></td>
427
- <td align="center"><a href="https://github.com/dewald-els"><img src="https://avatars.githubusercontent.com/u/10051247?v=4" width="100px;" alt=""/><br /><sub><b>Dewald Els</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=dewald-els" title="Code">💻</a></td>
428
- <td align="center"><a href="https://github.com/joewoodhouse"><img src="https://avatars.githubusercontent.com/u/3168135?v=4" width="100px;" alt=""/><br /><sub><b>Joe Woodhouse</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=joewoodhouse" title="Documentation">📖</a></td>
429
- <td align="center"><a href="https://github.com/ptasheq"><img src="https://avatars.githubusercontent.com/u/3025106?v=4" width="100px;" alt=""/><br /><sub><b>Ptasheq</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=ptasheq" title="Documentation">📖</a></td>
430
- <td align="center"><a href="https://github.com/victorybiz"><img src="https://avatars.githubusercontent.com/u/8276466?v=4" width="100px;" alt=""/><br /><sub><b>Victory Osayi</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=victorybiz" title="Code">💻</a></td>
431
- <td align="center"><a href="https://github.com/tobiasmuecksch"><img src="https://avatars.githubusercontent.com/u/1294854?v=4" width="100px;" alt=""/><br /><sub><b>Tobias Mücksch</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=tobiasmuecksch" title="Code">💻</a></td>
432
- <td align="center"><a href="https://github.com/dragermrb"><img src="https://avatars.githubusercontent.com/u/11479696?v=4" width="100px;" alt=""/><br /><sub><b>Manuel Rodríguez</b></sub></a><br /><a href="https://github.com/capacitor-community/sqlite/commits?author=dragermrb" title="Code">💻</a></td>
433
- </tr>
434
- </table>
450
+ <p align="center">
451
+ <a href="https://github.com/jepiqueau"><img src="https://github.com/jepiqueau.png?size=100" width="50" height="50" /></a>
452
+ <a href="https://github.com/paulantoine2"><img src="https://github.com/paulantoine2.png?size=100" width="50" height="50" /></a>
453
+ <a href="https://github.com/karyfars"><img src="https://github.com/karyfars.png?size=100" width="50" height="50" /></a>
454
+ <a href="https://github.com/chriswep"><img src="https://github.com/chriswep.png?size=100" width="50" height="50" /></a>
455
+ <a href="https://github.com/nirajhinge"><img src="https://github.com/nirajhinge.png?size=100" width="50" height="50" /></a>
456
+ <a href="https://github.com/digaus"><img src="https://github.com/digaus.png?size=100" width="50" height="50" /></a>
457
+ <a href="https://github.com/IT-MikeS"><img src="https://github.com/IT-MikeS.png?size=100" width="50" height="50" /></a>
458
+ <a href="https://github.com/peakcool"><img src="https://github.com/peakcool.png?size=100" width="50" height="50" /></a>
459
+ <a href="https://github.com/gion-andri"><img src="https://github.com/gion-andri.png?size=100" width="50" height="50" /></a>
460
+ <a href="https://github.com/robingenz"><img src="https://github.com/robingenz.png?size=100" width="50" height="50" /></a>
461
+ <a href="https://github.com/dewald-els"><img src="https://github.com/dewald-els.png?size=100" width="50" height="50" /></a>
462
+ <a href="https://github.com/joewoodhouse"><img src="https://github.com/joewoodhouse.png?size=100" width="50" height="50" /></a>
463
+ <a href="https://github.com/ptasheq"><img src="https://github.com/ptasheq.png?size=100" width="50" height="50" /></a>
464
+ <a href="https://github.com/victorybiz"><img src="https://github.com/victorybiz.png?size=100" width="50" height="50" /></a>
465
+ <a href="https://github.com/tobiasmuecksch"><img src="https://github.com/tobiasmuecksch.png?size=100" width="50" height="50" /></a>
466
+ <a href="https://github.com/dragermrb"><img src="https://github.com/dragermrb.png?size=100" width="50" height="50" /></a>
467
+ <a href="https://github.com/iamcco"><img src="https://github.com/iamcco.png?size=100" width="50" height="50" /></a>
468
+ </p>
435
469
 
436
470
  <!-- markdownlint-enable -->
437
471
  <!-- prettier-ignore-end -->
@@ -864,6 +864,10 @@ public class CapacitorSQLite {
864
864
  Database db = dbDict.get(dbName);
865
865
  if (db != null) {
866
866
  try {
867
+ if (!db.isOpen()) {
868
+ String msg = "CreateSyncTable: db not opened";
869
+ throw new Exception(msg);
870
+ }
867
871
  JSObject res = db.createSyncTable();
868
872
  return res;
869
873
  } catch (Exception e) {
@@ -880,6 +884,10 @@ public class CapacitorSQLite {
880
884
  Database db = dbDict.get(dbName);
881
885
  if (db != null) {
882
886
  try {
887
+ if (!db.isOpen()) {
888
+ String msg = "SetSyncDate: db not opened";
889
+ throw new Exception(msg);
890
+ }
883
891
  db.setSyncDate(syncDate);
884
892
  return;
885
893
  } catch (Exception e) {
@@ -896,6 +904,10 @@ public class CapacitorSQLite {
896
904
  Database db = dbDict.get(dbName);
897
905
  if (db != null) {
898
906
  try {
907
+ if (!db.isOpen()) {
908
+ String msg = "GetSyncDate: db not opened";
909
+ throw new Exception(msg);
910
+ }
899
911
  long syncDate = db.getSyncDate();
900
912
  return syncDate;
901
913
  } catch (Exception e) {
@@ -1011,9 +1023,15 @@ public class CapacitorSQLite {
1011
1023
  Database db = dbDict.get(dbName);
1012
1024
  if (db != null) {
1013
1025
  try {
1026
+ if (!db.isOpen()) {
1027
+ String msg = "ExportToJson: db not opened";
1028
+ throw new Exception(msg);
1029
+ }
1014
1030
  JSObject ret = db.exportToJson(expMode);
1015
-
1016
- if (ret.length() == 5 || ret.length() == 6 || ret.length() == 7) {
1031
+ if (ret.length() == 0) {
1032
+ String msg = "ExportToJson: : return Object is empty " + "No data to synchronize";
1033
+ throw new Exception(msg);
1034
+ } else if (ret.length() == 5 || ret.length() == 6 || ret.length() == 7) {
1017
1035
  return ret;
1018
1036
  } else {
1019
1037
  String msg = "ExportToJson: return Obj is not a JsonSQLite Obj";
@@ -1029,6 +1047,27 @@ public class CapacitorSQLite {
1029
1047
  }
1030
1048
  }
1031
1049
 
1050
+ public void deleteExportedRows(String dbName) throws Exception {
1051
+ dbName = getDatabaseName(dbName);
1052
+ Database db = dbDict.get(dbName);
1053
+ if (db != null) {
1054
+ try {
1055
+ if (!db.isOpen()) {
1056
+ String msg = "deleteExportedRows: db not opened";
1057
+ throw new Exception(msg);
1058
+ }
1059
+ db.deleteExportedRows();
1060
+ return;
1061
+ } catch (Exception e) {
1062
+ String msg = "DeleteExportedRows " + e.getMessage();
1063
+ throw new Exception(msg);
1064
+ }
1065
+ } else {
1066
+ String msg = "No available connection for database " + dbName;
1067
+ throw new Exception(msg);
1068
+ }
1069
+ }
1070
+
1032
1071
  public void copyFromAssets(Boolean overwrite) throws Exception {
1033
1072
  String msg = "copy failed : ";
1034
1073
  try {
@@ -1259,6 +1259,32 @@ public class CapacitorSQLitePlugin extends Plugin {
1259
1259
  }
1260
1260
  }
1261
1261
 
1262
+ @PluginMethod
1263
+ public void deleteExportedRows(PluginCall call) {
1264
+ JSObject retObj = new JSObject();
1265
+ JsonSQLite retJson = new JsonSQLite();
1266
+ if (!call.getData().has("database")) {
1267
+ String msg = "ExportToJson: Must provide a database name";
1268
+ rHandler.retResult(call, null, msg);
1269
+ return;
1270
+ }
1271
+ String dbName = call.getString("database");
1272
+ if (implementation != null) {
1273
+ try {
1274
+ implementation.deleteExportedRows(dbName);
1275
+ rHandler.retResult(call, null, null);
1276
+ return;
1277
+ } catch (Exception e) {
1278
+ String msg = "DeleteExportedRows: " + e.getMessage();
1279
+ rHandler.retResult(call, null, msg);
1280
+ return;
1281
+ }
1282
+ } else {
1283
+ rHandler.retResult(call, null, loadMessage);
1284
+ return;
1285
+ }
1286
+ }
1287
+
1262
1288
  /**
1263
1289
  * CopyFromAssets
1264
1290
  * copy all databases from public/assets/databases to application folder
@@ -52,7 +52,7 @@ public class NotificationCenter {
52
52
  public synchronized void postNotification(String notificationName, Map<String, Object> _info) {
53
53
  ArrayList<MyRunnable> list = registredObjects.get(notificationName);
54
54
  if (list != null) {
55
- for (MyRunnable r : list) {
55
+ for (MyRunnable r : new ArrayList<>(list)) {
56
56
  r.setInfo(_info);
57
57
  r.run();
58
58
  }