@capacitor-community/sqlite 5.0.7-1 → 5.0.7

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 +6 -1
  2. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +123 -1
  3. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +112 -0
  4. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +140 -78
  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 +96 -11
  11. package/dist/esm/definitions.js +99 -50
  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 +143 -50
  17. package/dist/plugin.cjs.js.map +1 -1
  18. package/dist/plugin.js +143 -50
  19. package/dist/plugin.js.map +1 -1
  20. package/electron/dist/plugin.js +1102 -260
  21. package/electron/dist/plugin.js.map +1 -1
  22. package/ios/Plugin/CapacitorSQLite.swift +119 -0
  23. package/ios/Plugin/CapacitorSQLitePlugin.m +4 -0
  24. package/ios/Plugin/CapacitorSQLitePlugin.swift +128 -0
  25. package/ios/Plugin/Database.swift +76 -0
  26. package/ios/Plugin/ImportExportJson/ImportFromJson.swift +13 -2
  27. package/ios/Plugin/Utils/UtilsDelete.swift +116 -114
  28. package/ios/Plugin/Utils/UtilsSQLCipher.swift +10 -3
  29. package/ios/Plugin/Utils/UtilsSQLStatement.swift +84 -84
  30. package/ios/Plugin/Utils/UtilsUpgrade.swift +3 -0
  31. package/package.json +2 -2
  32. package/src/definitions.ts +187 -53
  33. package/src/web.ts +48 -0
package/dist/plugin.js CHANGED
@@ -471,40 +471,69 @@ var capacitorCapacitorSQLite = (function (exports, core) {
471
471
  return Promise.reject(err);
472
472
  }
473
473
  }
474
+ async beginTransaction() {
475
+ try {
476
+ const changes = await this.sqlite
477
+ .beginTransaction({ database: this.dbName });
478
+ return Promise.resolve(changes);
479
+ }
480
+ catch (err) {
481
+ return Promise.reject(err);
482
+ }
483
+ }
484
+ async commitTransaction() {
485
+ try {
486
+ const changes = await this.sqlite
487
+ .commitTransaction({ database: this.dbName });
488
+ return Promise.resolve(changes);
489
+ }
490
+ catch (err) {
491
+ return Promise.reject(err);
492
+ }
493
+ }
494
+ async rollbackTransaction() {
495
+ try {
496
+ const changes = await this.sqlite
497
+ .rollbackTransaction({ database: this.dbName });
498
+ return Promise.resolve(changes);
499
+ }
500
+ catch (err) {
501
+ return Promise.reject(err);
502
+ }
503
+ }
504
+ async isTransactionActive() {
505
+ try {
506
+ const result = await this.sqlite
507
+ .isTransactionActive({ database: this.dbName });
508
+ return Promise.resolve(result);
509
+ }
510
+ catch (err) {
511
+ return Promise.reject(err);
512
+ }
513
+ }
474
514
  async loadExtension(path) {
475
515
  try {
476
- console.log(`database: ${this.dbName}`);
477
- console.log(`readonly: ${this.readonly}}`);
478
- console.log(`path: ${path}}`);
479
516
  await this.sqlite.loadExtension({
480
517
  database: this.dbName,
481
518
  path: path,
482
519
  readonly: this.readonly,
483
520
  });
484
- console.log(`loadExtension successful`);
485
521
  return Promise.resolve();
486
522
  }
487
523
  catch (err) {
488
- console.log(`loadExtension failed `);
489
524
  return Promise.reject(err);
490
525
  }
491
526
  }
492
527
  async enableLoadExtension(toggle) {
493
528
  try {
494
- console.log(`database: ${this.dbName}`);
495
- console.log(`readonly: ${this.readonly}`);
496
- console.log(`toggle: ${toggle}`);
497
529
  await this.sqlite.enableLoadExtension({
498
530
  database: this.dbName,
499
531
  toggle: toggle,
500
532
  readonly: this.readonly,
501
533
  });
502
- console.log(`enableLoadExtension successful`);
503
534
  return Promise.resolve();
504
535
  }
505
536
  catch (err) {
506
- console.log(err);
507
- console.log(`enableLoadExtension failed `);
508
537
  return Promise.reject(err);
509
538
  }
510
539
  }
@@ -544,7 +573,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
544
573
  return Promise.reject(err);
545
574
  }
546
575
  }
547
- async execute(statements, transaction = true) {
576
+ async execute(statements, transaction = true, isSQL92 = true) {
548
577
  try {
549
578
  if (!this.readonly) {
550
579
  const res = await this.sqlite.execute({
@@ -552,6 +581,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
552
581
  statements: statements,
553
582
  transaction: transaction,
554
583
  readonly: false,
584
+ isSQL92: isSQL92
555
585
  });
556
586
  return Promise.resolve(res);
557
587
  }
@@ -563,7 +593,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
563
593
  return Promise.reject(err);
564
594
  }
565
595
  }
566
- async query(statement, values) {
596
+ async query(statement, values, isSQL92 = true) {
567
597
  let res;
568
598
  try {
569
599
  if (values && values.length > 0) {
@@ -572,6 +602,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
572
602
  statement: statement,
573
603
  values: values,
574
604
  readonly: this.readonly,
605
+ isSql92: true
575
606
  });
576
607
  }
577
608
  else {
@@ -580,6 +611,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
580
611
  statement: statement,
581
612
  values: [],
582
613
  readonly: this.readonly,
614
+ isSQL92: isSQL92
583
615
  });
584
616
  }
585
617
  // reorder rows for ios
@@ -590,7 +622,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
590
622
  return Promise.reject(err);
591
623
  }
592
624
  }
593
- async run(statement, values, transaction = true, returnMode = 'no') {
625
+ async run(statement, values, transaction = true, returnMode = 'no', isSQL92 = true) {
594
626
  let res;
595
627
  try {
596
628
  if (!this.readonly) {
@@ -605,6 +637,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
605
637
  transaction: transaction,
606
638
  readonly: false,
607
639
  returnMode: mRetMode,
640
+ isSQL92: true
608
641
  });
609
642
  // }
610
643
  }
@@ -619,6 +652,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
619
652
  transaction: transaction,
620
653
  readonly: false,
621
654
  returnMode: mRetMode,
655
+ isSQL92: isSQL92
622
656
  });
623
657
  }
624
658
  // reorder rows for ios
@@ -633,7 +667,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
633
667
  return Promise.reject(err);
634
668
  }
635
669
  }
636
- async executeSet(set, transaction = true, returnMode = 'no') {
670
+ async executeSet(set, transaction = true, returnMode = 'no', isSQL92 = true) {
637
671
  let res;
638
672
  try {
639
673
  if (!this.readonly) {
@@ -643,6 +677,7 @@ var capacitorCapacitorSQLite = (function (exports, core) {
643
677
  transaction: transaction,
644
678
  readonly: false,
645
679
  returnMode: returnMode,
680
+ isSQL92: isSQL92
646
681
  });
647
682
  // }
648
683
  // reorder rows for ios
@@ -791,17 +826,25 @@ var capacitorCapacitorSQLite = (function (exports, core) {
791
826
  return Promise.reject(err);
792
827
  }
793
828
  }
794
- async executeTransaction(txn) {
795
- try {
796
- if (!this.readonly) {
797
- const ret = await this.sqlite.execute({
798
- database: this.dbName,
799
- statements: 'BEGIN TRANSACTION;',
800
- transaction: false,
829
+ async executeTransaction(txn, isSQL92 = true) {
830
+ let changes = 0;
831
+ let isActive = false;
832
+ if (!this.readonly) {
833
+ try {
834
+ await this.sqlite.beginTransaction({
835
+ database: this.dbName
836
+ });
837
+ isActive = await this.sqlite.isTransactionActive({
838
+ database: this.dbName
801
839
  });
802
- if (ret.changes.changes < 0) {
803
- return Promise.reject('Error in BEGIN TRANSACTION');
840
+ if (!isActive) {
841
+ return Promise.reject('After Begin Transaction, no transaction active');
804
842
  }
843
+ }
844
+ catch (err) {
845
+ return Promise.reject(err);
846
+ }
847
+ try {
805
848
  for (const task of txn) {
806
849
  if (task.values && task.values.length > 0) {
807
850
  const retMode = task.statement.toUpperCase().includes('RETURNING')
@@ -814,11 +857,12 @@ var capacitorCapacitorSQLite = (function (exports, core) {
814
857
  transaction: false,
815
858
  readonly: false,
816
859
  returnMode: retMode,
860
+ isSQL92: isSQL92
817
861
  });
818
- if (ret.changes.lastId === -1) {
819
- await this.execute('ROLLBACK;', false);
820
- return Promise.reject('Error in transaction run ');
862
+ if (ret.changes.changes <= 0) {
863
+ throw new Error('Error in transaction method run ');
821
864
  }
865
+ changes += ret.changes.changes;
822
866
  }
823
867
  else {
824
868
  const ret = await this.sqlite.execute({
@@ -827,37 +871,42 @@ var capacitorCapacitorSQLite = (function (exports, core) {
827
871
  transaction: false,
828
872
  readonly: false,
829
873
  });
874
+ isActive = await this.sqlite.isTransactionActive({
875
+ database: this.dbName
876
+ });
830
877
  if (ret.changes.changes < 0) {
831
- await this.sqlite.execute({
832
- database: this.dbName,
833
- statements: 'ROLLBACK;',
834
- transaction: false,
835
- readonly: false,
836
- });
837
- return Promise.reject('Error in transaction execute ');
878
+ throw new Error('Error in transaction method execute ');
838
879
  }
880
+ changes += ret.changes.changes;
839
881
  }
840
882
  }
841
- await this.sqlite.execute({
842
- database: this.dbName,
843
- statements: 'COMMIT;',
844
- transaction: false,
845
- readonly: false,
883
+ isActive = await this.sqlite.isTransactionActive({
884
+ database: this.dbName
846
885
  });
847
- return Promise.resolve();
886
+ if (isActive) {
887
+ const retC = await this.sqlite.commitTransaction({
888
+ database: this.dbName
889
+ });
890
+ changes += retC.changes.changes;
891
+ }
892
+ const retChanges = { changes: { changes: changes } };
893
+ return Promise.resolve(retChanges);
848
894
  }
849
- else {
850
- return Promise.reject('not allowed in read-only mode');
895
+ catch (err) {
896
+ const msg = err.message ? err.message : err;
897
+ isActive = await this.sqlite.isTransactionActive({
898
+ database: this.dbName
899
+ });
900
+ if (isActive) {
901
+ await this.sqlite.rollbackTransaction({
902
+ database: this.dbName,
903
+ });
904
+ }
905
+ return Promise.reject(msg);
851
906
  }
852
907
  }
853
- catch (err) {
854
- await this.sqlite.execute({
855
- database: this.dbName,
856
- statements: 'ROLLBACK;',
857
- transaction: false,
858
- readonly: false,
859
- });
860
- return Promise.reject(err);
908
+ else {
909
+ return Promise.reject('not allowed in read-only mode');
861
910
  }
862
911
  }
863
912
  async reorderRows(res) {
@@ -1019,6 +1068,50 @@ var capacitorCapacitorSQLite = (function (exports, core) {
1019
1068
  throw new Error(`${err}`);
1020
1069
  }
1021
1070
  }
1071
+ async beginTransaction(options) {
1072
+ this.ensureJeepSqliteIsAvailable();
1073
+ this.ensureWebstoreIsOpen();
1074
+ try {
1075
+ const changes = await this.jeepSqliteElement.beginTransaction(options);
1076
+ return changes;
1077
+ }
1078
+ catch (err) {
1079
+ throw new Error(`${err}`);
1080
+ }
1081
+ }
1082
+ async commitTransaction(options) {
1083
+ this.ensureJeepSqliteIsAvailable();
1084
+ this.ensureWebstoreIsOpen();
1085
+ try {
1086
+ const changes = await this.jeepSqliteElement.commitTransaction(options);
1087
+ return changes;
1088
+ }
1089
+ catch (err) {
1090
+ throw new Error(`${err}`);
1091
+ }
1092
+ }
1093
+ async rollbackTransaction(options) {
1094
+ this.ensureJeepSqliteIsAvailable();
1095
+ this.ensureWebstoreIsOpen();
1096
+ try {
1097
+ const changes = await this.jeepSqliteElement.rollbackTransaction(options);
1098
+ return changes;
1099
+ }
1100
+ catch (err) {
1101
+ throw new Error(`${err}`);
1102
+ }
1103
+ }
1104
+ async isTransactionActive(options) {
1105
+ this.ensureJeepSqliteIsAvailable();
1106
+ this.ensureWebstoreIsOpen();
1107
+ try {
1108
+ const result = await this.jeepSqliteElement.isTransactionActive(options);
1109
+ return result;
1110
+ }
1111
+ catch (err) {
1112
+ throw new Error(`${err}`);
1113
+ }
1114
+ }
1022
1115
  async getTableList(options) {
1023
1116
  this.ensureJeepSqliteIsAvailable();
1024
1117
  this.ensureWebstoreIsOpen();