@capacitor-community/sqlite 3.4.2-5 → 3.4.3-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.
Files changed (33) hide show
  1. package/README.md +46 -4
  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 +102 -86
  7. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +127 -38
  8. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/UtilsJson.java +90 -0
  9. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +8 -4
  10. package/dist/esm/definitions.d.ts +17 -1
  11. package/dist/esm/definitions.js +22 -28
  12. package/dist/esm/definitions.js.map +1 -1
  13. package/dist/esm/web.d.ts +20 -11
  14. package/dist/esm/web.js +288 -473
  15. package/dist/esm/web.js.map +1 -1
  16. package/dist/plugin.cjs.js +286 -477
  17. package/dist/plugin.cjs.js.map +1 -1
  18. package/dist/plugin.js +1036 -1227
  19. package/dist/plugin.js.map +1 -1
  20. package/electron/dist/plugin.js +589 -744
  21. package/electron/dist/plugin.js.map +1 -1
  22. package/ios/Plugin/CapacitorSQLite.swift +34 -1
  23. package/ios/Plugin/CapacitorSQLitePlugin.m +1 -0
  24. package/ios/Plugin/CapacitorSQLitePlugin.swift +25 -0
  25. package/ios/Plugin/Database.swift +29 -1
  26. package/ios/Plugin/Extensions/String.swift +8 -0
  27. package/ios/Plugin/ImportExportJson/ExportToJson.swift +190 -32
  28. package/ios/Plugin/ImportExportJson/ImportFromJson.swift +73 -38
  29. package/ios/Plugin/Utils/UtilsDrop.swift +2 -2
  30. package/ios/Plugin/Utils/UtilsJson.swift +68 -1
  31. package/ios/Plugin/Utils/UtilsSQLCipher.swift +277 -29
  32. package/ios/Plugin/Utils/UtilsUpgrade.swift +33 -13
  33. package/package.json +6 -6
@@ -420,19 +420,21 @@ class SQLiteDBConnection {
420
420
  values: [],
421
421
  });
422
422
  }
423
- if (Object.keys(res.values[0]).includes('ios_columns')) {
424
- const columnList = res.values[0]['ios_columns'];
425
- const iosRes = [];
426
- for (let i = 1; i < res.values.length; i++) {
427
- const rowJson = res.values[i];
428
- const resRowJson = {};
429
- for (const item of columnList) {
430
- resRowJson[item] = rowJson[item];
423
+ if (res && typeof res.values[0] === 'object') {
424
+ if (Object.keys(res.values[0]).includes('ios_columns')) {
425
+ const columnList = res.values[0]['ios_columns'];
426
+ const iosRes = [];
427
+ for (let i = 1; i < res.values.length; i++) {
428
+ const rowJson = res.values[i];
429
+ const resRowJson = {};
430
+ for (const item of columnList) {
431
+ resRowJson[item] = rowJson[item];
432
+ }
433
+ iosRes.push(resRowJson);
431
434
  }
432
- iosRes.push(resRowJson);
435
+ res = {};
436
+ res['values'] = iosRes;
433
437
  }
434
- res = {};
435
- res['values'] = iosRes;
436
438
  }
437
439
  return Promise.resolve(res);
438
440
  }
@@ -572,6 +574,15 @@ class SQLiteDBConnection {
572
574
  return Promise.reject(err);
573
575
  }
574
576
  }
577
+ async deleteExportedRows() {
578
+ try {
579
+ await this.sqlite.deleteExportedRows({ database: this.dbName });
580
+ return Promise.resolve();
581
+ }
582
+ catch (err) {
583
+ return Promise.reject(err);
584
+ }
585
+ }
575
586
  async executeTransaction(txn) {
576
587
  try {
577
588
  const ret = await this.sqlite.execute({
@@ -628,23 +639,6 @@ class SQLiteDBConnection {
628
639
  }
629
640
  }
630
641
  }
631
- /*
632
- if (Object.keys(res.values[0]).includes("ios_columns")) {
633
- const columnList = res.values[0]["ios_columns"];
634
- console.log(`in DBconnection query ${columnList}`);
635
- const iosRes = []
636
- for (let i = 1; i < res.values.length; i++) {
637
- const rowJson = res.values[i];
638
- const resRowJson = {};
639
- for (const item of columnList) {
640
- resRowJson[item] = rowJson[item];
641
- }
642
- console.log(`resRowJson: ${JSON.stringify(resRowJson)}`)
643
- iosRes.push(resRowJson);
644
- }
645
- console.log(`iosRes ${JSON.stringify(iosRes)}`);
646
- }
647
- */
648
642
 
649
643
  const CapacitorSQLite = core.registerPlugin('CapacitorSQLite', {
650
644
  web: () => Promise.resolve().then(function () { return web; }).then(m => new m.CapacitorSQLiteWeb()),
@@ -654,563 +648,351 @@ const CapacitorSQLite = core.registerPlugin('CapacitorSQLite', {
654
648
  class CapacitorSQLiteWeb extends core.WebPlugin {
655
649
  constructor() {
656
650
  super(...arguments);
657
- this.sqliteEl = null;
658
- this.isStoreOpen = false;
651
+ this.jeepSqliteElement = null;
652
+ this.isWebStoreOpen = false;
659
653
  }
660
654
  async initWebStore() {
661
655
  await customElements.whenDefined('jeep-sqlite');
662
- this.sqliteEl = document.querySelector('jeep-sqlite');
663
- if (this.sqliteEl != null) {
664
- this.sqliteEl.addEventListener('jeepSqliteImportProgress', (event) => {
665
- this.notifyListeners('sqliteImportProgressEvent', event.detail);
666
- });
667
- this.sqliteEl.addEventListener('jeepSqliteExportProgress', (event) => {
668
- this.notifyListeners('sqliteExportProgressEvent', event.detail);
669
- });
670
- if (!this.isStoreOpen)
671
- this.isStoreOpen = await this.sqliteEl.isStoreOpen();
672
- return Promise.resolve();
673
- }
674
- else {
675
- return Promise.reject('InitWeb: this.sqliteEl is null');
676
- }
656
+ this.jeepSqliteElement = document.querySelector('jeep-sqlite');
657
+ this.ensureJeepSqliteIsAvailable();
658
+ this.jeepSqliteElement.addEventListener('jeepSqliteImportProgress', (event) => {
659
+ this.notifyListeners('sqliteImportProgressEvent', event.detail);
660
+ });
661
+ this.jeepSqliteElement.addEventListener('jeepSqliteExportProgress', (event) => {
662
+ this.notifyListeners('sqliteExportProgressEvent', event.detail);
663
+ });
664
+ if (!this.isWebStoreOpen) {
665
+ this.isWebStoreOpen = await this.jeepSqliteElement.isStoreOpen();
666
+ }
667
+ return;
677
668
  }
678
669
  async saveToStore(options) {
679
- if (this.sqliteEl != null) {
680
- if (this.isStoreOpen) {
681
- try {
682
- await this.sqliteEl.saveToStore(options);
683
- return Promise.resolve();
684
- }
685
- catch (err) {
686
- return Promise.reject(`${err}`);
687
- }
688
- }
689
- else {
690
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
691
- }
670
+ this.ensureJeepSqliteIsAvailable();
671
+ this.ensureWebstoreIsOpen();
672
+ try {
673
+ await this.jeepSqliteElement.saveToStore(options);
674
+ return;
692
675
  }
693
- else {
694
- throw this.unimplemented('Not implemented on web.');
676
+ catch (err) {
677
+ throw new Error(`${err}`);
695
678
  }
696
679
  }
697
680
  async echo(options) {
698
- if (this.sqliteEl != null) {
699
- const echo = await this.sqliteEl.echo(options);
700
- return echo;
701
- }
702
- else {
703
- throw this.unimplemented('Not implemented on web.');
704
- }
705
- }
706
- async isSecretStored() {
707
- throw this.unimplemented('Not implemented on web.');
708
- }
709
- async setEncryptionSecret(options) {
710
- console.log('setEncryptionSecret', options);
711
- throw this.unimplemented('Not implemented on web.');
712
- }
713
- async changeEncryptionSecret(options) {
714
- console.log('changeEncryptionSecret', options);
715
- throw this.unimplemented('Not implemented on web.');
716
- }
717
- async getNCDatabasePath(options) {
718
- console.log('getNCDatabasePath', options);
719
- throw this.unimplemented('Not implemented on web.');
720
- }
721
- async createNCConnection(options) {
722
- console.log('createNCConnection', options);
723
- throw this.unimplemented('Not implemented on web.');
724
- }
725
- async closeNCConnection(options) {
726
- console.log('closeNCConnection', options);
727
- throw this.unimplemented('Not implemented on web.');
728
- }
729
- async isNCDatabase(options) {
730
- console.log('isNCDatabase', options);
731
- throw this.unimplemented('Not implemented on web.');
681
+ this.ensureJeepSqliteIsAvailable();
682
+ const echoResult = await this.jeepSqliteElement.echo(options);
683
+ return echoResult;
732
684
  }
733
685
  async createConnection(options) {
734
- if (this.sqliteEl != null) {
735
- if (this.isStoreOpen) {
736
- try {
737
- await this.sqliteEl.createConnection(options);
738
- return Promise.resolve();
739
- }
740
- catch (err) {
741
- return Promise.reject(`${err}`);
742
- }
743
- }
744
- else {
745
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
746
- }
686
+ this.ensureJeepSqliteIsAvailable();
687
+ this.ensureWebstoreIsOpen();
688
+ try {
689
+ await this.jeepSqliteElement.createConnection(options);
690
+ return;
747
691
  }
748
- else {
749
- throw this.unimplemented('Not implemented on web.');
692
+ catch (err) {
693
+ throw new Error(`${err}`);
750
694
  }
751
695
  }
752
696
  async open(options) {
753
- if (this.sqliteEl != null) {
754
- if (this.isStoreOpen) {
755
- try {
756
- await this.sqliteEl.open(options);
757
- return Promise.resolve();
758
- }
759
- catch (err) {
760
- return Promise.reject(`${err}`);
761
- }
762
- }
763
- else {
764
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
765
- }
697
+ this.ensureJeepSqliteIsAvailable();
698
+ this.ensureWebstoreIsOpen();
699
+ try {
700
+ await this.jeepSqliteElement.open(options);
701
+ return;
766
702
  }
767
- else {
768
- throw this.unimplemented('Not implemented on web.');
703
+ catch (err) {
704
+ throw new Error(`${err}`);
769
705
  }
770
706
  }
771
707
  async closeConnection(options) {
772
- if (this.sqliteEl != null) {
773
- if (this.isStoreOpen) {
774
- try {
775
- await this.sqliteEl.closeConnection(options);
776
- return Promise.resolve();
777
- }
778
- catch (err) {
779
- return Promise.reject(`${err}`);
780
- }
781
- }
782
- else {
783
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
784
- }
708
+ this.ensureJeepSqliteIsAvailable();
709
+ this.ensureWebstoreIsOpen();
710
+ try {
711
+ await this.jeepSqliteElement.closeConnection(options);
712
+ return;
785
713
  }
786
- else {
787
- throw this.unimplemented('Not implemented on web.');
714
+ catch (err) {
715
+ throw new Error(`${err}`);
788
716
  }
789
717
  }
790
- async getUrl() {
791
- throw this.unimplemented('Not implemented on web.');
792
- }
793
718
  async getVersion(options) {
794
- if (this.sqliteEl != null) {
795
- if (this.isStoreOpen) {
796
- try {
797
- const ret = await this.sqliteEl.getVersion(options);
798
- return Promise.resolve(ret);
799
- }
800
- catch (err) {
801
- return Promise.reject(`${err}`);
802
- }
803
- }
804
- else {
805
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
806
- }
719
+ this.ensureJeepSqliteIsAvailable();
720
+ this.ensureWebstoreIsOpen();
721
+ try {
722
+ const versionResult = await this.jeepSqliteElement.getVersion(options);
723
+ return versionResult;
807
724
  }
808
- else {
809
- throw this.unimplemented('Not implemented on web.');
725
+ catch (err) {
726
+ throw new Error(`${err}`);
810
727
  }
811
728
  }
812
729
  async checkConnectionsConsistency(options) {
813
- if (this.sqliteEl != null) {
814
- try {
815
- const ret = await this.sqliteEl.checkConnectionsConsistency(options);
816
- return Promise.resolve(ret);
817
- }
818
- catch (err) {
819
- return Promise.reject(`${err}`);
820
- }
730
+ this.ensureJeepSqliteIsAvailable();
731
+ try {
732
+ const consistencyResult = await this.jeepSqliteElement.checkConnectionsConsistency(options);
733
+ return consistencyResult;
821
734
  }
822
- else {
823
- throw this.unimplemented('Not implemented on web.');
735
+ catch (err) {
736
+ throw new Error(`${err}`);
824
737
  }
825
738
  }
826
739
  async close(options) {
827
- if (this.sqliteEl != null) {
828
- if (this.isStoreOpen) {
829
- try {
830
- await this.sqliteEl.close(options);
831
- return Promise.resolve();
832
- }
833
- catch (err) {
834
- return Promise.reject(`${err}`);
835
- }
836
- }
837
- else {
838
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
839
- }
740
+ this.ensureJeepSqliteIsAvailable();
741
+ this.ensureWebstoreIsOpen();
742
+ try {
743
+ await this.jeepSqliteElement.close(options);
744
+ return;
840
745
  }
841
- else {
842
- throw this.unimplemented('Not implemented on web.');
746
+ catch (err) {
747
+ throw new Error(`${err}`);
843
748
  }
844
749
  }
845
750
  async getTableList(options) {
846
- if (this.sqliteEl != null) {
847
- if (this.isStoreOpen) {
848
- try {
849
- const res = await this.sqliteEl.getTableList(options);
850
- return Promise.resolve(res);
851
- }
852
- catch (err) {
853
- return Promise.reject(`${err}`);
854
- }
855
- }
856
- else {
857
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
858
- }
751
+ this.ensureJeepSqliteIsAvailable();
752
+ this.ensureWebstoreIsOpen();
753
+ try {
754
+ const tableListResult = await this.jeepSqliteElement.getTableList(options);
755
+ return tableListResult;
859
756
  }
860
- else {
861
- throw this.unimplemented('Not implemented on web.');
757
+ catch (err) {
758
+ throw new Error(`${err}`);
862
759
  }
863
760
  }
864
761
  async execute(options) {
865
- if (this.sqliteEl != null) {
866
- if (this.isStoreOpen) {
867
- try {
868
- const ret = await this.sqliteEl.execute(options);
869
- return Promise.resolve(ret);
870
- }
871
- catch (err) {
872
- return Promise.reject(`${err}`);
873
- }
874
- }
875
- else {
876
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
877
- }
762
+ this.ensureJeepSqliteIsAvailable();
763
+ this.ensureWebstoreIsOpen();
764
+ try {
765
+ const executeResult = await this.jeepSqliteElement.execute(options);
766
+ return executeResult;
878
767
  }
879
- else {
880
- throw this.unimplemented('Not implemented on web.');
768
+ catch (err) {
769
+ throw new Error(`${err}`);
881
770
  }
882
771
  }
883
772
  async executeSet(options) {
884
- if (this.sqliteEl != null) {
885
- if (this.isStoreOpen) {
886
- try {
887
- const ret = await this.sqliteEl.executeSet(options);
888
- return Promise.resolve(ret);
889
- }
890
- catch (err) {
891
- return Promise.reject(`${err}`);
892
- }
893
- }
894
- else {
895
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
896
- }
773
+ this.ensureJeepSqliteIsAvailable();
774
+ this.ensureWebstoreIsOpen();
775
+ try {
776
+ const executeResult = await this.jeepSqliteElement.executeSet(options);
777
+ return executeResult;
897
778
  }
898
- else {
899
- throw this.unimplemented('Not implemented on web.');
779
+ catch (err) {
780
+ throw new Error(`${err}`);
900
781
  }
901
782
  }
902
783
  async run(options) {
903
- if (this.sqliteEl != null) {
904
- if (this.isStoreOpen) {
905
- try {
906
- const ret = await this.sqliteEl.run(options);
907
- return Promise.resolve(ret);
908
- }
909
- catch (err) {
910
- return Promise.reject(`${err}`);
911
- }
912
- }
913
- else {
914
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
915
- }
784
+ this.ensureJeepSqliteIsAvailable();
785
+ this.ensureWebstoreIsOpen();
786
+ try {
787
+ const runResult = await this.jeepSqliteElement.run(options);
788
+ return runResult;
916
789
  }
917
- else {
918
- throw this.unimplemented('Not implemented on web.');
790
+ catch (err) {
791
+ throw new Error(`${err}`);
919
792
  }
920
793
  }
921
794
  async query(options) {
922
- if (this.sqliteEl != null) {
923
- if (this.isStoreOpen) {
924
- try {
925
- const ret = await this.sqliteEl.query(options);
926
- return Promise.resolve(ret);
927
- }
928
- catch (err) {
929
- return Promise.reject(`${err}`);
930
- }
931
- }
932
- else {
933
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
934
- }
795
+ this.ensureJeepSqliteIsAvailable();
796
+ this.ensureWebstoreIsOpen();
797
+ try {
798
+ const queryResult = await this.jeepSqliteElement.query(options);
799
+ return queryResult;
935
800
  }
936
- else {
937
- throw this.unimplemented('Not implemented on web.');
801
+ catch (err) {
802
+ throw new Error(`${err}`);
938
803
  }
939
804
  }
940
805
  async isDBExists(options) {
941
- if (this.sqliteEl != null) {
942
- if (this.isStoreOpen) {
943
- try {
944
- const ret = await this.sqliteEl.isDBExists(options);
945
- return Promise.resolve(ret);
946
- }
947
- catch (err) {
948
- return Promise.reject(`${err}`);
949
- }
950
- }
951
- else {
952
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
953
- }
806
+ this.ensureJeepSqliteIsAvailable();
807
+ this.ensureWebstoreIsOpen();
808
+ try {
809
+ const dbExistsResult = await this.jeepSqliteElement.isDBExists(options);
810
+ return dbExistsResult;
954
811
  }
955
- else {
956
- throw this.unimplemented('Not implemented on web.');
812
+ catch (err) {
813
+ throw new Error(`${err}`);
957
814
  }
958
815
  }
959
816
  async isDBOpen(options) {
960
- if (this.sqliteEl != null) {
961
- if (this.isStoreOpen) {
962
- try {
963
- const ret = await this.sqliteEl.isDBOpen(options);
964
- return Promise.resolve(ret);
965
- }
966
- catch (err) {
967
- return Promise.reject(`${err}`);
968
- }
969
- }
970
- else {
971
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
972
- }
817
+ this.ensureJeepSqliteIsAvailable();
818
+ this.ensureWebstoreIsOpen();
819
+ try {
820
+ const isDBOpenResult = await this.jeepSqliteElement.isDBOpen(options);
821
+ return isDBOpenResult;
973
822
  }
974
- else {
975
- throw this.unimplemented('Not implemented on web.');
823
+ catch (err) {
824
+ throw new Error(`${err}`);
976
825
  }
977
826
  }
978
827
  async isDatabase(options) {
979
- if (this.sqliteEl != null) {
980
- if (!this.isStoreOpen)
981
- this.isStoreOpen = await this.sqliteEl.isStoreOpen();
982
- if (this.isStoreOpen) {
983
- try {
984
- const ret = await this.sqliteEl.isDatabase(options);
985
- return Promise.resolve(ret);
986
- }
987
- catch (err) {
988
- return Promise.reject(`${err}`);
989
- }
990
- }
991
- else {
992
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
993
- }
828
+ this.ensureJeepSqliteIsAvailable();
829
+ this.ensureWebstoreIsOpen();
830
+ try {
831
+ const isDatabaseResult = await this.jeepSqliteElement.isDatabase(options);
832
+ return isDatabaseResult;
994
833
  }
995
- else {
996
- throw this.unimplemented('Not implemented on web.');
834
+ catch (err) {
835
+ throw new Error(`${err}`);
997
836
  }
998
837
  }
999
838
  async isTableExists(options) {
1000
- if (this.sqliteEl != null) {
1001
- if (this.isStoreOpen) {
1002
- try {
1003
- const ret = await this.sqliteEl.isTableExists(options);
1004
- return Promise.resolve(ret);
1005
- }
1006
- catch (err) {
1007
- return Promise.reject(`${err}`);
1008
- }
1009
- }
1010
- else {
1011
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
1012
- }
839
+ this.ensureJeepSqliteIsAvailable();
840
+ this.ensureWebstoreIsOpen();
841
+ try {
842
+ const tableExistsResult = await this.jeepSqliteElement.isTableExists(options);
843
+ return tableExistsResult;
1013
844
  }
1014
- else {
1015
- throw this.unimplemented('Not implemented on web.');
845
+ catch (err) {
846
+ throw new Error(`${err}`);
1016
847
  }
1017
848
  }
1018
849
  async deleteDatabase(options) {
1019
- if (this.sqliteEl != null) {
1020
- if (this.isStoreOpen) {
1021
- try {
1022
- await this.sqliteEl.deleteDatabase(options);
1023
- return Promise.resolve();
1024
- }
1025
- catch (err) {
1026
- return Promise.reject(`${err}`);
1027
- }
1028
- }
1029
- else {
1030
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
1031
- }
850
+ this.ensureJeepSqliteIsAvailable();
851
+ this.ensureWebstoreIsOpen();
852
+ try {
853
+ await this.jeepSqliteElement.deleteDatabase(options);
854
+ return;
1032
855
  }
1033
- else {
1034
- throw this.unimplemented('Not implemented on web.');
856
+ catch (err) {
857
+ throw new Error(`${err}`);
1035
858
  }
1036
859
  }
1037
860
  async isJsonValid(options) {
1038
- if (this.sqliteEl != null) {
1039
- if (!this.isStoreOpen)
1040
- this.isStoreOpen = await this.sqliteEl.isStoreOpen();
1041
- if (this.isStoreOpen) {
1042
- try {
1043
- const ret = await this.sqliteEl.isJsonValid(options);
1044
- return Promise.resolve(ret);
1045
- }
1046
- catch (err) {
1047
- return Promise.reject(`${err}`);
1048
- }
1049
- }
1050
- else {
1051
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
1052
- }
861
+ this.ensureJeepSqliteIsAvailable();
862
+ this.ensureWebstoreIsOpen();
863
+ try {
864
+ const isJsonValidResult = await this.jeepSqliteElement.isJsonValid(options);
865
+ return isJsonValidResult;
1053
866
  }
1054
- else {
1055
- throw this.unimplemented('Not implemented on web.');
867
+ catch (err) {
868
+ throw new Error(`${err}`);
1056
869
  }
1057
870
  }
1058
871
  async importFromJson(options) {
1059
- if (this.sqliteEl != null) {
1060
- if (!this.isStoreOpen)
1061
- this.isStoreOpen = await this.sqliteEl.isStoreOpen();
1062
- if (this.isStoreOpen) {
1063
- try {
1064
- const ret = await this.sqliteEl.importFromJson(options);
1065
- return Promise.resolve(ret);
1066
- }
1067
- catch (err) {
1068
- return Promise.reject(`${err}`);
1069
- }
1070
- }
1071
- else {
1072
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
1073
- }
872
+ this.ensureJeepSqliteIsAvailable();
873
+ this.ensureWebstoreIsOpen();
874
+ try {
875
+ const importFromJsonResult = await this.jeepSqliteElement.importFromJson(options);
876
+ return importFromJsonResult;
1074
877
  }
1075
- else {
1076
- throw this.unimplemented('Not implemented on web.');
878
+ catch (err) {
879
+ throw new Error(`${err}`);
1077
880
  }
1078
881
  }
1079
882
  async exportToJson(options) {
1080
- if (this.sqliteEl != null) {
1081
- if (this.isStoreOpen) {
1082
- try {
1083
- const ret = await this.sqliteEl.exportToJson(options);
1084
- return Promise.resolve(ret);
1085
- }
1086
- catch (err) {
1087
- return Promise.reject(`${err}`);
1088
- }
1089
- }
1090
- else {
1091
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
1092
- }
883
+ this.ensureJeepSqliteIsAvailable();
884
+ this.ensureWebstoreIsOpen();
885
+ try {
886
+ const exportToJsonResult = await this.jeepSqliteElement.exportToJson(options);
887
+ return exportToJsonResult;
1093
888
  }
1094
- else {
1095
- throw this.unimplemented('Not implemented on web.');
889
+ catch (err) {
890
+ throw new Error(`${err}`);
1096
891
  }
1097
892
  }
1098
893
  async createSyncTable(options) {
1099
- if (this.sqliteEl != null) {
1100
- if (this.isStoreOpen) {
1101
- try {
1102
- const ret = await this.sqliteEl.createSyncTable(options);
1103
- return Promise.resolve(ret);
1104
- }
1105
- catch (err) {
1106
- return Promise.reject(`${err}`);
1107
- }
1108
- }
1109
- else {
1110
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
1111
- }
894
+ this.ensureJeepSqliteIsAvailable();
895
+ this.ensureWebstoreIsOpen();
896
+ try {
897
+ const createSyncTableResult = await this.jeepSqliteElement.createSyncTable(options);
898
+ return createSyncTableResult;
1112
899
  }
1113
- else {
1114
- throw this.unimplemented('Not implemented on web.');
900
+ catch (err) {
901
+ throw new Error(`${err}`);
1115
902
  }
1116
903
  }
1117
904
  async setSyncDate(options) {
1118
- if (this.sqliteEl != null) {
1119
- if (this.isStoreOpen) {
1120
- try {
1121
- await this.sqliteEl.setSyncDate(options);
1122
- return Promise.resolve();
1123
- }
1124
- catch (err) {
1125
- return Promise.reject(`${err}`);
1126
- }
1127
- }
1128
- else {
1129
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
1130
- }
905
+ this.ensureJeepSqliteIsAvailable();
906
+ this.ensureWebstoreIsOpen();
907
+ try {
908
+ await this.jeepSqliteElement.setSyncDate(options);
909
+ return;
1131
910
  }
1132
- else {
1133
- throw this.unimplemented('Not implemented on web.');
911
+ catch (err) {
912
+ throw new Error(`${err}`);
1134
913
  }
1135
914
  }
1136
915
  async getSyncDate(options) {
1137
- if (this.sqliteEl != null) {
1138
- if (this.isStoreOpen) {
1139
- try {
1140
- const ret = await this.sqliteEl.getSyncDate(options);
1141
- return Promise.resolve(ret);
1142
- }
1143
- catch (err) {
1144
- return Promise.reject(`${err}`);
1145
- }
1146
- }
1147
- else {
1148
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
1149
- }
916
+ this.ensureJeepSqliteIsAvailable();
917
+ this.ensureWebstoreIsOpen();
918
+ try {
919
+ const getSyncDateResult = await this.jeepSqliteElement.getSyncDate(options);
920
+ return getSyncDateResult;
1150
921
  }
1151
- else {
1152
- throw this.unimplemented('Not implemented on web.');
922
+ catch (err) {
923
+ throw new Error(`${err}`);
924
+ }
925
+ }
926
+ async deleteExportedRows(options) {
927
+ this.ensureJeepSqliteIsAvailable();
928
+ this.ensureWebstoreIsOpen();
929
+ try {
930
+ await this.jeepSqliteElement.deleteExportedRows(options);
931
+ return;
932
+ }
933
+ catch (err) {
934
+ throw new Error(`${err}`);
1153
935
  }
1154
936
  }
1155
937
  async addUpgradeStatement(options) {
1156
- if (this.sqliteEl != null) {
1157
- if (this.isStoreOpen) {
1158
- try {
1159
- await this.sqliteEl.addUpgradeStatement(options);
1160
- return Promise.resolve();
1161
- }
1162
- catch (err) {
1163
- return Promise.reject(`${err}`);
1164
- }
1165
- }
1166
- else {
1167
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
1168
- }
938
+ this.ensureJeepSqliteIsAvailable();
939
+ this.ensureWebstoreIsOpen();
940
+ try {
941
+ await this.jeepSqliteElement.addUpgradeStatement(options);
942
+ return;
1169
943
  }
1170
- else {
1171
- throw this.unimplemented('Not implemented on web.');
944
+ catch (err) {
945
+ throw new Error(`${err}`);
1172
946
  }
1173
947
  }
1174
948
  async copyFromAssets(options) {
1175
- if (this.sqliteEl != null) {
1176
- if (this.isStoreOpen) {
1177
- try {
1178
- await this.sqliteEl.copyFromAssets(options);
1179
- return Promise.resolve();
1180
- }
1181
- catch (err) {
1182
- return Promise.reject(`${err}`);
1183
- }
1184
- }
1185
- else {
1186
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
1187
- }
949
+ this.ensureJeepSqliteIsAvailable();
950
+ this.ensureWebstoreIsOpen();
951
+ try {
952
+ await this.jeepSqliteElement.copyFromAssets(options);
953
+ return;
1188
954
  }
1189
- else {
1190
- throw this.unimplemented('Not implemented on web.');
955
+ catch (err) {
956
+ throw new Error(`${err}`);
1191
957
  }
1192
958
  }
1193
959
  async getDatabaseList() {
1194
- if (this.sqliteEl != null) {
1195
- if (!this.isStoreOpen)
1196
- this.isStoreOpen = await this.sqliteEl.isStoreOpen();
1197
- if (this.isStoreOpen) {
1198
- try {
1199
- const ret = await this.sqliteEl.getDatabaseList();
1200
- return Promise.resolve(ret);
1201
- }
1202
- catch (err) {
1203
- return Promise.reject(`${err}`);
1204
- }
1205
- }
1206
- else {
1207
- return Promise.reject(`Store "jeepSqliteStore" failed to open`);
1208
- }
960
+ this.ensureJeepSqliteIsAvailable();
961
+ this.ensureWebstoreIsOpen();
962
+ try {
963
+ const databaseListResult = await this.jeepSqliteElement.getDatabaseList();
964
+ return databaseListResult;
1209
965
  }
1210
- else {
1211
- throw this.unimplemented('Not implemented on web.');
966
+ catch (err) {
967
+ throw new Error(`${err}`);
1212
968
  }
1213
969
  }
970
+ /**
971
+ * Checks if the `jeep-sqlite` element is present in the DOM.
972
+ * If it's not in the DOM, this method throws an Error.
973
+ *
974
+ * Attention: This will always fail, if the `intWebStore()` method wasn't called before.
975
+ */
976
+ ensureJeepSqliteIsAvailable() {
977
+ if (this.jeepSqliteElement === null) {
978
+ throw new Error(`The jeep-sqlite element is not present in the DOM! Please check the @capacitor-community/sqlite documentation for instructions regarding the web platform.`);
979
+ }
980
+ }
981
+ ensureWebstoreIsOpen() {
982
+ if (!this.isWebStoreOpen) {
983
+ /**
984
+ * if (!this.isWebStoreOpen)
985
+ this.isWebStoreOpen = await this.jeepSqliteElement.isStoreOpen();
986
+ */
987
+ throw new Error('WebStore is not open yet. You have to call "initWebStore()" first.');
988
+ }
989
+ }
990
+ ////////////////////////////////////
991
+ ////// UNIMPLEMENTED METHODS
992
+ ////////////////////////////////////
993
+ async getUrl() {
994
+ throw this.unimplemented('Not implemented on web.');
995
+ }
1214
996
  async getMigratableDbList(options) {
1215
997
  console.log('getMigratableDbList', options);
1216
998
  throw this.unimplemented('Not implemented on web.');
@@ -1223,11 +1005,38 @@ class CapacitorSQLiteWeb extends core.WebPlugin {
1223
1005
  console.log('deleteOldDatabases', options);
1224
1006
  throw this.unimplemented('Not implemented on web.');
1225
1007
  }
1008
+ async isSecretStored() {
1009
+ throw this.unimplemented('Not implemented on web.');
1010
+ }
1011
+ async setEncryptionSecret(options) {
1012
+ console.log('setEncryptionSecret', options);
1013
+ throw this.unimplemented('Not implemented on web.');
1014
+ }
1015
+ async changeEncryptionSecret(options) {
1016
+ console.log('changeEncryptionSecret', options);
1017
+ throw this.unimplemented('Not implemented on web.');
1018
+ }
1019
+ async getNCDatabasePath(options) {
1020
+ console.log('getNCDatabasePath', options);
1021
+ throw this.unimplemented('Not implemented on web.');
1022
+ }
1023
+ async createNCConnection(options) {
1024
+ console.log('createNCConnection', options);
1025
+ throw this.unimplemented('Not implemented on web.');
1026
+ }
1027
+ async closeNCConnection(options) {
1028
+ console.log('closeNCConnection', options);
1029
+ throw this.unimplemented('Not implemented on web.');
1030
+ }
1031
+ async isNCDatabase(options) {
1032
+ console.log('isNCDatabase', options);
1033
+ throw this.unimplemented('Not implemented on web.');
1034
+ }
1226
1035
  }
1227
1036
 
1228
1037
  var web = /*#__PURE__*/Object.freeze({
1229
- __proto__: null,
1230
- CapacitorSQLiteWeb: CapacitorSQLiteWeb
1038
+ __proto__: null,
1039
+ CapacitorSQLiteWeb: CapacitorSQLiteWeb
1231
1040
  });
1232
1041
 
1233
1042
  exports.CapacitorSQLite = CapacitorSQLite;