@capacitor-community/sqlite 3.4.3-3 β†’ 3.5.1-1

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 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
 
@@ -51,7 +51,7 @@ The main change is related to the delete table's rows when a synchronization tab
51
51
 
52
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
53
 
54
- - On successfull completion of your synchronization management process with the remote server database, you must
54
+ - On successful completion of your synchronization management process with the remote server database, you must
55
55
  - Set a new synchronization date (as `(new Date()).toISOString()`) with the `setSyncDate` method.
56
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
57
 
@@ -400,6 +400,8 @@ No configuration required for this plugin
400
400
 
401
401
  - [angular-sqlite-app-starter](https://github.com/jepiqueau/angular-sqlite-app-starter)
402
402
 
403
+ - [angular-sqlite-synchronize-app](https://github.com/jepiqueau/angular-sqlite-synchronize-app)
404
+
403
405
  ### Ionic/React
404
406
 
405
407
  - [react-sqlite-app-starter](https://github.com/jepiqueau/react-sqlite-app-starter)
@@ -445,26 +447,26 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
445
447
  <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
446
448
  <!-- prettier-ignore-start -->
447
449
  <!-- markdownlint-disable -->
448
- <table>
449
- <tr>
450
- <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>
451
- <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>
452
- <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>
453
- <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>
454
- <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>
455
- <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>
456
- <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>
457
- <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>
458
- <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>
459
- <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>
460
- <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>
461
- <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>
462
- <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>
463
- <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>
464
- <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>
465
- <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>
466
- </tr>
467
- </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
+ <a href="https://github.com/eltociear"><img src="https://github.com/eltociear.png?size=100" width="50" height="50" /></a>
469
+ </p>
468
470
 
469
471
  <!-- markdownlint-enable -->
470
472
  <!-- prettier-ignore-end -->
@@ -517,7 +517,8 @@ public class Database {
517
517
  String sqlStmt = statement;
518
518
  try {
519
519
  Boolean isLast = _uJson.isLastModified(mDB);
520
- if (isLast) {
520
+ Boolean isDel = _uJson.isSqlDeleted(mDB);
521
+ if (isLast && isDel) {
521
522
  // Replace DELETE by UPDATE and set sql_deleted to 1
522
523
  Integer wIdx = statement.toUpperCase().indexOf("WHERE");
523
524
  String preStmt = statement.substring(0, wIdx - 1);
@@ -770,7 +771,8 @@ public class Database {
770
771
  boolean isExists = _uJson.isTableExists(this, "sync_table");
771
772
  if (!isExists) {
772
773
  boolean isLastModified = _uJson.isLastModified(this);
773
- if (isLastModified) {
774
+ boolean isSqlDeleted = _uJson.isSqlDeleted(this);
775
+ if (isLastModified && isSqlDeleted) {
774
776
  Date date = new Date();
775
777
  long syncTime = date.getTime() / 1000L;
776
778
  String[] statements = {
@@ -159,6 +159,7 @@ public class ImportFromJson {
159
159
  ArrayList<String> statements = new ArrayList<>();
160
160
  String stmt = new StringBuilder("CREATE TABLE IF NOT EXISTS ").append(tableName).append(" (").toString();
161
161
  Boolean isLastModified = false;
162
+ Boolean isSqlDeleted = false;
162
163
  for (int j = 0; j < mSchema.size(); j++) {
163
164
  if (j == mSchema.size() - 1) {
164
165
  if (mSchema.get(j).getColumn() != null) {
@@ -167,6 +168,9 @@ public class ImportFromJson {
167
168
  if (mSchema.get(j).getColumn().equals("last_modified")) {
168
169
  isLastModified = true;
169
170
  }
171
+ if (mSchema.get(j).getColumn().equals("sql_deleted")) {
172
+ isSqlDeleted = true;
173
+ }
170
174
  } else if (mSchema.get(j).getForeignkey() != null) {
171
175
  stmt =
172
176
  new StringBuilder(stmt)
@@ -196,6 +200,9 @@ public class ImportFromJson {
196
200
  if (mSchema.get(j).getColumn().equals("last_modified")) {
197
201
  isLastModified = true;
198
202
  }
203
+ if (mSchema.get(j).getColumn().equals("sql_deleted")) {
204
+ isSqlDeleted = true;
205
+ }
199
206
  } else if (mSchema.get(j).getForeignkey() != null) {
200
207
  stmt =
201
208
  new StringBuilder(stmt)
@@ -219,7 +226,7 @@ public class ImportFromJson {
219
226
  }
220
227
  stmt = new StringBuilder(stmt).append(");").toString();
221
228
  statements.add(stmt);
222
- if (isLastModified) {
229
+ if (isLastModified && isSqlDeleted) {
223
230
  // create trigger last_modified associated with the table
224
231
  String stmtTrigger = new StringBuilder("CREATE TRIGGER IF NOT EXISTS ")
225
232
  .append(tableName)
@@ -19,6 +19,12 @@ public class UtilsJson {
19
19
  private JsonView uJView = new JsonView();
20
20
  private UtilsDrop _uDrop = new UtilsDrop();
21
21
 
22
+ /**
23
+ * Check existence of last_modified column
24
+ * @param db
25
+ * @return
26
+ * @throws Exception
27
+ */
22
28
  public boolean isLastModified(Database db) throws Exception {
23
29
  if (!db.isOpen()) {
24
30
  throw new Exception("isLastModified: Database not opened");
@@ -40,6 +46,33 @@ public class UtilsJson {
40
46
  }
41
47
  }
42
48
 
49
+ /**
50
+ * Check existence of sql_deleted column
51
+ * @param db
52
+ * @return
53
+ * @throws Exception
54
+ */
55
+ public boolean isSqlDeleted(Database db) throws Exception {
56
+ if (!db.isOpen()) {
57
+ throw new Exception("isSqlDeleted: Database not opened");
58
+ }
59
+ boolean ret = false;
60
+ try {
61
+ List<String> tables = _uDrop.getTablesNames(db);
62
+ for (String tableName : tables) {
63
+ JSObject namesTypes = getTableColumnNamesTypes(db, tableName);
64
+ ArrayList<String> colNames = (ArrayList<String>) namesTypes.get("names");
65
+ if (colNames.contains("sql_deleted")) {
66
+ ret = true;
67
+ break;
68
+ }
69
+ }
70
+ return ret;
71
+ } catch (Exception e) {
72
+ throw new Exception("isSqlDeleted: " + e.getMessage());
73
+ }
74
+ }
75
+
43
76
  /**
44
77
  * Check if a table exists
45
78
  *
@@ -1108,10 +1108,10 @@ export interface ISQLiteDBConnection {
1108
1108
  * @returns Promise<void>
1109
1109
  * @since 3.4.0
1110
1110
  */
1111
- executeTransaction(txn: [{
1111
+ executeTransaction(txn: {
1112
1112
  statement: string;
1113
1113
  values?: any[];
1114
- }]): Promise<void>;
1114
+ }[]): Promise<void>;
1115
1115
  }
1116
1116
  /**
1117
1117
  * SQLiteDBConnection Class
@@ -1139,8 +1139,8 @@ export declare class SQLiteDBConnection implements ISQLiteDBConnection {
1139
1139
  getSyncDate(): Promise<string>;
1140
1140
  exportToJson(mode: string): Promise<capSQLiteJson>;
1141
1141
  deleteExportedRows(): Promise<void>;
1142
- executeTransaction(txn: [{
1142
+ executeTransaction(txn: {
1143
1143
  statement: string;
1144
1144
  values?: any[];
1145
- }]): Promise<void>;
1145
+ }[]): Promise<void>;
1146
1146
  }
@@ -470,7 +470,8 @@ class UtilsSQLite {
470
470
  let sqlStmt = statement;
471
471
  try {
472
472
  const isLast = await this.isLastModified(db, true);
473
- if (isLast) {
473
+ const isDel = await this.isSqlDeleted(db, true);
474
+ if (isLast && isDel) {
474
475
  // Replace DELETE by UPDATE and set sql_deleted to 1
475
476
  const wIdx = statement.toUpperCase().indexOf('WHERE');
476
477
  const preStmt = statement.substring(0, wIdx - 1);
@@ -671,6 +672,29 @@ class UtilsSQLite {
671
672
  return Promise.reject(`isLastModified: ${err}`);
672
673
  }
673
674
  }
675
+ /**
676
+ * isSqlDeleted
677
+ * @param db
678
+ * @param isOpen
679
+ */
680
+ async isSqlDeleted(db, isOpen) {
681
+ if (!isOpen) {
682
+ return Promise.reject('isSqlDeleted: database not opened');
683
+ }
684
+ try {
685
+ const tableList = await this.getTablesNames(db);
686
+ for (const table of tableList) {
687
+ const tableNamesTypes = await this.getTableColumnNamesTypes(db, table);
688
+ const tableColumnNames = tableNamesTypes.names;
689
+ if (tableColumnNames.includes('sql_deleted')) {
690
+ return Promise.resolve(true);
691
+ }
692
+ }
693
+ }
694
+ catch (err) {
695
+ return Promise.reject(`isSqlDeleted: ${err}`);
696
+ }
697
+ }
674
698
  /**
675
699
  * GetTableColumnNamesTypes
676
700
  * @param mDB
@@ -820,6 +844,7 @@ class UtilsJson {
820
844
  async createSchemaStatement(jsonData) {
821
845
  const statements = [];
822
846
  let isLastModified = false;
847
+ let isSqlDeleted = false;
823
848
  // Prepare the statement to execute
824
849
  try {
825
850
  for (const jTable of jsonData.tables) {
@@ -833,6 +858,9 @@ class UtilsJson {
833
858
  if (jTable.schema[j].column === 'last_modified') {
834
859
  isLastModified = true;
835
860
  }
861
+ if (jTable.schema[j].column === 'sql_deleted') {
862
+ isSqlDeleted = true;
863
+ }
836
864
  }
837
865
  else if (jTable.schema[j].foreignkey) {
838
866
  statements.push(`FOREIGN KEY (${jTable.schema[j].foreignkey}) ${jTable.schema[j].value}`);
@@ -847,6 +875,9 @@ class UtilsJson {
847
875
  if (jTable.schema[j].column === 'last_modified') {
848
876
  isLastModified = true;
849
877
  }
878
+ if (jTable.schema[j].column === 'sql_deleted') {
879
+ isSqlDeleted = true;
880
+ }
850
881
  }
851
882
  else if (jTable.schema[j].foreignkey) {
852
883
  statements.push(`FOREIGN KEY (${jTable.schema[j].foreignkey}) ${jTable.schema[j].value},`);
@@ -857,7 +888,7 @@ class UtilsJson {
857
888
  }
858
889
  }
859
890
  statements.push(');');
860
- if (isLastModified) {
891
+ if (isLastModified && isSqlDeleted) {
861
892
  // create trigger last_modified associated with the table
862
893
  let trig = 'CREATE TRIGGER IF NOT EXISTS ';
863
894
  trig += `${jTable.name}`;
@@ -3443,7 +3474,8 @@ class Database {
3443
3474
  const retB = await this.jsonUtil.isTableExists(this.database, isOpen, 'sync_table');
3444
3475
  if (!retB) {
3445
3476
  const isLastModified = await this.sqliteUtil.isLastModified(this.database, isOpen);
3446
- if (isLastModified) {
3477
+ const isSqlDeleted = await this.sqliteUtil.isSqlDeleted(this.database, isOpen);
3478
+ if (isLastModified && isSqlDeleted) {
3447
3479
  const date = Math.round(new Date().getTime() / 1000);
3448
3480
  let stmts = `
3449
3481
  CREATE TABLE IF NOT EXISTS sync_table (