@pisell/core 1.0.61 → 1.0.62
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/es/app/app.d.ts +2 -0
- package/es/app/app.js +4 -0
- package/es/communicationManager/index.d.ts +59 -0
- package/es/communicationManager/index.js +174 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +2 -1
- package/es/indexDB/index.d.ts +46 -1
- package/es/indexDB/index.js +715 -335
- package/es/locales/index.js +7 -5
- package/es/locales/ja.d.ts +3 -0
- package/es/locales/ja.js +5 -0
- package/es/locales/pt.d.ts +3 -0
- package/es/locales/pt.js +5 -0
- package/es/routes/index.d.ts +1 -1
- package/es/tasks/index.d.ts +1 -1
- package/lib/app/app.d.ts +2 -0
- package/lib/app/app.js +4 -0
- package/lib/communicationManager/index.d.ts +59 -0
- package/lib/communicationManager/index.js +102 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/indexDB/index.d.ts +46 -1
- package/lib/indexDB/index.js +226 -0
- package/lib/locales/index.js +7 -5
- package/lib/locales/ja.d.ts +3 -0
- package/lib/locales/ja.js +29 -0
- package/lib/locales/pt.d.ts +3 -0
- package/lib/locales/pt.js +29 -0
- package/lib/routes/index.d.ts +1 -1
- package/lib/tasks/index.d.ts +1 -1
- package/package.json +1 -1
package/es/indexDB/index.js
CHANGED
|
@@ -554,6 +554,131 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
554
554
|
}
|
|
555
555
|
return flushDebouncedUpdate;
|
|
556
556
|
}()
|
|
557
|
+
/**
|
|
558
|
+
* 批量添加数据到指定的存储对象
|
|
559
|
+
* @param {string} storeName - 存储对象名称
|
|
560
|
+
* @param {T[]} dataList - 要批量添加的数据数组
|
|
561
|
+
* @param {boolean} [log=false] - 是否记录日志
|
|
562
|
+
* @returns {Promise<T[]>} 成功添加的数据数组
|
|
563
|
+
* @template T
|
|
564
|
+
*/
|
|
565
|
+
)
|
|
566
|
+
}, {
|
|
567
|
+
key: "bulkAdd",
|
|
568
|
+
value: (function () {
|
|
569
|
+
var _bulkAdd = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(storeName, dataList) {
|
|
570
|
+
var _this6 = this;
|
|
571
|
+
var log,
|
|
572
|
+
storeConfig,
|
|
573
|
+
keyPath,
|
|
574
|
+
memStore,
|
|
575
|
+
uuid,
|
|
576
|
+
_args6 = arguments;
|
|
577
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
578
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
579
|
+
case 0:
|
|
580
|
+
log = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : false;
|
|
581
|
+
if (!(!dataList || dataList.length === 0)) {
|
|
582
|
+
_context6.next = 3;
|
|
583
|
+
break;
|
|
584
|
+
}
|
|
585
|
+
return _context6.abrupt("return", []);
|
|
586
|
+
case 3:
|
|
587
|
+
if (this.useIndexDB) {
|
|
588
|
+
_context6.next = 9;
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
591
|
+
// 使用内存存储
|
|
592
|
+
storeConfig = this.stores.find(function (s) {
|
|
593
|
+
return s.name === storeName;
|
|
594
|
+
});
|
|
595
|
+
keyPath = (storeConfig === null || storeConfig === void 0 ? void 0 : storeConfig.keyPath) || 'id';
|
|
596
|
+
memStore = this.getMemoryStore(storeName);
|
|
597
|
+
dataList.forEach(function (data) {
|
|
598
|
+
var key = data[keyPath];
|
|
599
|
+
memStore.set(key, data);
|
|
600
|
+
});
|
|
601
|
+
return _context6.abrupt("return", dataList);
|
|
602
|
+
case 9:
|
|
603
|
+
uuid = "[ IndexDB ] BULK_ADD: - ".concat(storeName, " - ").concat(dayjs().valueOf());
|
|
604
|
+
if (log) {
|
|
605
|
+
this.app.logger.addLog({
|
|
606
|
+
type: 'info',
|
|
607
|
+
title: uuid,
|
|
608
|
+
metadata: {
|
|
609
|
+
msg: '批量添加数据前',
|
|
610
|
+
count: dataList.length
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
return _context6.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
615
|
+
var hasExistingData;
|
|
616
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
617
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
618
|
+
case 0:
|
|
619
|
+
if (_this6.db) {
|
|
620
|
+
_context5.next = 3;
|
|
621
|
+
break;
|
|
622
|
+
}
|
|
623
|
+
if (log) {
|
|
624
|
+
_this6.app.logger.addLog({
|
|
625
|
+
type: 'error',
|
|
626
|
+
title: uuid,
|
|
627
|
+
metadata: {
|
|
628
|
+
msg: '批量添加数据前 数据库未连接',
|
|
629
|
+
count: dataList.length
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
throw new Error('数据库未连接');
|
|
634
|
+
case 3:
|
|
635
|
+
_context5.prev = 3;
|
|
636
|
+
_context5.next = 6;
|
|
637
|
+
return _this6.db.table(storeName).bulkAdd(dataList);
|
|
638
|
+
case 6:
|
|
639
|
+
if (log) {
|
|
640
|
+
_this6.app.logger.addLog({
|
|
641
|
+
type: 'info',
|
|
642
|
+
title: uuid,
|
|
643
|
+
metadata: {
|
|
644
|
+
msg: '批量添加成功',
|
|
645
|
+
count: dataList.length
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
return _context5.abrupt("return", dataList);
|
|
650
|
+
case 10:
|
|
651
|
+
_context5.prev = 10;
|
|
652
|
+
_context5.t0 = _context5["catch"](3);
|
|
653
|
+
// 检查是否有部分数据已存在
|
|
654
|
+
hasExistingData = ((_context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.message) || '').includes('exists') || ((_context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.message) || '').includes('Key already exists');
|
|
655
|
+
_this6.app.logger.addLog({
|
|
656
|
+
type: hasExistingData ? 'info' : 'error',
|
|
657
|
+
title: uuid,
|
|
658
|
+
metadata: {
|
|
659
|
+
msg: '批量添加数据失败',
|
|
660
|
+
count: dataList.length,
|
|
661
|
+
error: _context5.t0.message
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
throw new Error(_context5.t0 === null || _context5.t0 === void 0 ? void 0 : _context5.t0.message);
|
|
665
|
+
case 15:
|
|
666
|
+
case "end":
|
|
667
|
+
return _context5.stop();
|
|
668
|
+
}
|
|
669
|
+
}, _callee5, null, [[3, 10]]);
|
|
670
|
+
}))(), "bulkAdd(".concat(storeName, ")")));
|
|
671
|
+
case 12:
|
|
672
|
+
case "end":
|
|
673
|
+
return _context6.stop();
|
|
674
|
+
}
|
|
675
|
+
}, _callee6, this);
|
|
676
|
+
}));
|
|
677
|
+
function bulkAdd(_x3, _x4) {
|
|
678
|
+
return _bulkAdd.apply(this, arguments);
|
|
679
|
+
}
|
|
680
|
+
return bulkAdd;
|
|
681
|
+
}()
|
|
557
682
|
/**
|
|
558
683
|
* 添加数据到指定的存储对象
|
|
559
684
|
* @param {string} storeName - 存储对象名称
|
|
@@ -566,21 +691,21 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
566
691
|
}, {
|
|
567
692
|
key: "add",
|
|
568
693
|
value: (function () {
|
|
569
|
-
var _add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
570
|
-
var
|
|
694
|
+
var _add = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(storeName, data) {
|
|
695
|
+
var _this7 = this;
|
|
571
696
|
var log,
|
|
572
697
|
storeConfig,
|
|
573
698
|
keyPath,
|
|
574
699
|
_key2,
|
|
575
700
|
memStore,
|
|
576
701
|
uuid,
|
|
577
|
-
|
|
578
|
-
return _regeneratorRuntime().wrap(function
|
|
579
|
-
while (1) switch (
|
|
702
|
+
_args8 = arguments;
|
|
703
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
704
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
580
705
|
case 0:
|
|
581
|
-
log =
|
|
706
|
+
log = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : false;
|
|
582
707
|
if (this.useIndexDB) {
|
|
583
|
-
|
|
708
|
+
_context8.next = 8;
|
|
584
709
|
break;
|
|
585
710
|
}
|
|
586
711
|
// 使用内存存储
|
|
@@ -591,7 +716,7 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
591
716
|
_key2 = data[keyPath];
|
|
592
717
|
memStore = this.getMemoryStore(storeName);
|
|
593
718
|
memStore.set(_key2, data);
|
|
594
|
-
return
|
|
719
|
+
return _context8.abrupt("return", data);
|
|
595
720
|
case 8:
|
|
596
721
|
uuid = "[ IndexDB ] ADD: - ".concat(storeName, " - ").concat(dayjs().valueOf());
|
|
597
722
|
if (log) {
|
|
@@ -601,17 +726,17 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
601
726
|
// metadata: { msg: '添加数据前', data: data }
|
|
602
727
|
// })
|
|
603
728
|
}
|
|
604
|
-
return
|
|
729
|
+
return _context8.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
605
730
|
var issExists;
|
|
606
|
-
return _regeneratorRuntime().wrap(function
|
|
607
|
-
while (1) switch (
|
|
731
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
732
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
608
733
|
case 0:
|
|
609
|
-
if (
|
|
610
|
-
|
|
734
|
+
if (_this7.db) {
|
|
735
|
+
_context7.next = 3;
|
|
611
736
|
break;
|
|
612
737
|
}
|
|
613
738
|
if (log) {
|
|
614
|
-
|
|
739
|
+
_this7.app.logger.addLog({
|
|
615
740
|
type: 'error',
|
|
616
741
|
title: uuid,
|
|
617
742
|
metadata: {
|
|
@@ -622,38 +747,38 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
622
747
|
}
|
|
623
748
|
throw new Error('数据库未连接');
|
|
624
749
|
case 3:
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
return
|
|
750
|
+
_context7.prev = 3;
|
|
751
|
+
_context7.next = 6;
|
|
752
|
+
return _this7.db.table(storeName).add(data);
|
|
628
753
|
case 6:
|
|
629
|
-
return
|
|
754
|
+
return _context7.abrupt("return", data);
|
|
630
755
|
case 9:
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
issExists = ((
|
|
634
|
-
|
|
756
|
+
_context7.prev = 9;
|
|
757
|
+
_context7.t0 = _context7["catch"](3);
|
|
758
|
+
issExists = ((_context7.t0 === null || _context7.t0 === void 0 ? void 0 : _context7.t0.message) || '').includes('exists'); // 如果错误信息中包含 'exists',则表示数据已存在,不报日志
|
|
759
|
+
_this7.app.logger.addLog({
|
|
635
760
|
type: issExists ? 'info' : 'error',
|
|
636
761
|
title: uuid,
|
|
637
762
|
metadata: {
|
|
638
763
|
msg: '添加数据失败',
|
|
639
764
|
data: data,
|
|
640
|
-
error:
|
|
765
|
+
error: _context7.t0.message
|
|
641
766
|
}
|
|
642
767
|
});
|
|
643
|
-
throw new Error(
|
|
768
|
+
throw new Error(_context7.t0 === null || _context7.t0 === void 0 ? void 0 : _context7.t0.message);
|
|
644
769
|
case 14:
|
|
645
770
|
case "end":
|
|
646
|
-
return
|
|
771
|
+
return _context7.stop();
|
|
647
772
|
}
|
|
648
|
-
},
|
|
773
|
+
}, _callee7, null, [[3, 9]]);
|
|
649
774
|
}))(), "add(".concat(storeName, ")")));
|
|
650
775
|
case 11:
|
|
651
776
|
case "end":
|
|
652
|
-
return
|
|
777
|
+
return _context8.stop();
|
|
653
778
|
}
|
|
654
|
-
},
|
|
779
|
+
}, _callee8, this);
|
|
655
780
|
}));
|
|
656
|
-
function add(
|
|
781
|
+
function add(_x5, _x6) {
|
|
657
782
|
return _add.apply(this, arguments);
|
|
658
783
|
}
|
|
659
784
|
return add;
|
|
@@ -668,54 +793,54 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
668
793
|
}, {
|
|
669
794
|
key: "exists",
|
|
670
795
|
value: (function () {
|
|
671
|
-
var _exists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
672
|
-
var
|
|
796
|
+
var _exists = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(storeName, key) {
|
|
797
|
+
var _this8 = this;
|
|
673
798
|
var memStore;
|
|
674
|
-
return _regeneratorRuntime().wrap(function
|
|
675
|
-
while (1) switch (
|
|
799
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
800
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
676
801
|
case 0:
|
|
677
802
|
if (this.useIndexDB) {
|
|
678
|
-
|
|
803
|
+
_context10.next = 3;
|
|
679
804
|
break;
|
|
680
805
|
}
|
|
681
806
|
// 使用内存存储
|
|
682
807
|
memStore = this.getMemoryStore(storeName);
|
|
683
|
-
return
|
|
808
|
+
return _context10.abrupt("return", memStore.has(key));
|
|
684
809
|
case 3:
|
|
685
|
-
return
|
|
810
|
+
return _context10.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
686
811
|
var result;
|
|
687
|
-
return _regeneratorRuntime().wrap(function
|
|
688
|
-
while (1) switch (
|
|
812
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
813
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
689
814
|
case 0:
|
|
690
|
-
if (
|
|
691
|
-
|
|
815
|
+
if (_this8.db) {
|
|
816
|
+
_context9.next = 2;
|
|
692
817
|
break;
|
|
693
818
|
}
|
|
694
819
|
throw new Error('数据库未连接');
|
|
695
820
|
case 2:
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
return
|
|
821
|
+
_context9.prev = 2;
|
|
822
|
+
_context9.next = 5;
|
|
823
|
+
return _this8.db.table(storeName).get(key);
|
|
699
824
|
case 5:
|
|
700
|
-
result =
|
|
701
|
-
return
|
|
825
|
+
result = _context9.sent;
|
|
826
|
+
return _context9.abrupt("return", result !== undefined);
|
|
702
827
|
case 9:
|
|
703
|
-
|
|
704
|
-
|
|
828
|
+
_context9.prev = 9;
|
|
829
|
+
_context9.t0 = _context9["catch"](2);
|
|
705
830
|
throw new Error('检查数据存在性失败');
|
|
706
831
|
case 12:
|
|
707
832
|
case "end":
|
|
708
|
-
return
|
|
833
|
+
return _context9.stop();
|
|
709
834
|
}
|
|
710
|
-
},
|
|
835
|
+
}, _callee9, null, [[2, 9]]);
|
|
711
836
|
}))(), "exists(".concat(storeName, ")")));
|
|
712
837
|
case 4:
|
|
713
838
|
case "end":
|
|
714
|
-
return
|
|
839
|
+
return _context10.stop();
|
|
715
840
|
}
|
|
716
|
-
},
|
|
841
|
+
}, _callee10, this);
|
|
717
842
|
}));
|
|
718
|
-
function exists(
|
|
843
|
+
function exists(_x7, _x8) {
|
|
719
844
|
return _exists.apply(this, arguments);
|
|
720
845
|
}
|
|
721
846
|
return exists;
|
|
@@ -732,17 +857,17 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
732
857
|
}, {
|
|
733
858
|
key: "get",
|
|
734
859
|
value: (function () {
|
|
735
|
-
var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
736
|
-
var
|
|
860
|
+
var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(storeName, key) {
|
|
861
|
+
var _this9 = this;
|
|
737
862
|
var log,
|
|
738
863
|
uuid,
|
|
739
864
|
_memStore$get,
|
|
740
865
|
memStore,
|
|
741
|
-
|
|
742
|
-
return _regeneratorRuntime().wrap(function
|
|
743
|
-
while (1) switch (
|
|
866
|
+
_args12 = arguments;
|
|
867
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
868
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
744
869
|
case 0:
|
|
745
|
-
log =
|
|
870
|
+
log = _args12.length > 2 && _args12[2] !== undefined ? _args12[2] : false;
|
|
746
871
|
uuid = "[ IndexDB ] GET: - ".concat(storeName, " - ").concat(key, " - ").concat(dayjs().valueOf());
|
|
747
872
|
if (log) {
|
|
748
873
|
// this.app.logger.addLog({
|
|
@@ -752,24 +877,24 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
752
877
|
// })
|
|
753
878
|
}
|
|
754
879
|
if (this.useIndexDB) {
|
|
755
|
-
|
|
880
|
+
_context12.next = 6;
|
|
756
881
|
break;
|
|
757
882
|
}
|
|
758
883
|
// 使用内存存储
|
|
759
884
|
memStore = this.getMemoryStore(storeName);
|
|
760
|
-
return
|
|
885
|
+
return _context12.abrupt("return", (_memStore$get = memStore.get(key)) !== null && _memStore$get !== void 0 ? _memStore$get : null);
|
|
761
886
|
case 6:
|
|
762
|
-
return
|
|
887
|
+
return _context12.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
|
|
763
888
|
var result;
|
|
764
|
-
return _regeneratorRuntime().wrap(function
|
|
765
|
-
while (1) switch (
|
|
889
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
890
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
766
891
|
case 0:
|
|
767
|
-
if (
|
|
768
|
-
|
|
892
|
+
if (_this9.db) {
|
|
893
|
+
_context11.next = 3;
|
|
769
894
|
break;
|
|
770
895
|
}
|
|
771
896
|
if (log) {
|
|
772
|
-
|
|
897
|
+
_this9.app.logger.addLog({
|
|
773
898
|
type: 'error',
|
|
774
899
|
title: uuid,
|
|
775
900
|
metadata: {
|
|
@@ -779,11 +904,11 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
779
904
|
}
|
|
780
905
|
throw new Error('数据库未连接');
|
|
781
906
|
case 3:
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
return
|
|
907
|
+
_context11.prev = 3;
|
|
908
|
+
_context11.next = 6;
|
|
909
|
+
return _this9.db.table(storeName).get(key);
|
|
785
910
|
case 6:
|
|
786
|
-
result =
|
|
911
|
+
result = _context11.sent;
|
|
787
912
|
if (log) {
|
|
788
913
|
// this.app.logger.addLog({
|
|
789
914
|
// type: 'info',
|
|
@@ -796,38 +921,160 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
796
921
|
// metadata: { msg: '事务完成' }
|
|
797
922
|
// });
|
|
798
923
|
}
|
|
799
|
-
return
|
|
924
|
+
return _context11.abrupt("return", result !== null && result !== void 0 ? result : null);
|
|
800
925
|
case 11:
|
|
801
|
-
|
|
802
|
-
|
|
926
|
+
_context11.prev = 11;
|
|
927
|
+
_context11.t0 = _context11["catch"](3);
|
|
803
928
|
if (log) {
|
|
804
|
-
|
|
929
|
+
_this9.app.logger.addLog({
|
|
805
930
|
type: 'error',
|
|
806
931
|
title: uuid,
|
|
807
932
|
metadata: {
|
|
808
933
|
msg: '获取失败',
|
|
809
|
-
error:
|
|
934
|
+
error: _context11.t0.message
|
|
810
935
|
}
|
|
811
936
|
});
|
|
812
937
|
}
|
|
813
938
|
throw new Error('获取数据失败');
|
|
814
939
|
case 15:
|
|
815
940
|
case "end":
|
|
816
|
-
return
|
|
941
|
+
return _context11.stop();
|
|
817
942
|
}
|
|
818
|
-
},
|
|
943
|
+
}, _callee11, null, [[3, 11]]);
|
|
819
944
|
}))(), "get(".concat(storeName, ")")));
|
|
820
945
|
case 7:
|
|
821
946
|
case "end":
|
|
822
|
-
return
|
|
947
|
+
return _context12.stop();
|
|
823
948
|
}
|
|
824
|
-
},
|
|
949
|
+
}, _callee12, this);
|
|
825
950
|
}));
|
|
826
|
-
function get(
|
|
951
|
+
function get(_x9, _x10) {
|
|
827
952
|
return _get.apply(this, arguments);
|
|
828
953
|
}
|
|
829
954
|
return get;
|
|
830
955
|
}()
|
|
956
|
+
/**
|
|
957
|
+
* 批量更新指定存储对象中的数据
|
|
958
|
+
* @param {string} storeName - 存储对象名称
|
|
959
|
+
* @param {T[]} dataList - 要批量更新的数据数组
|
|
960
|
+
* @param {boolean} [log=false] - 是否记录日志
|
|
961
|
+
* @returns {Promise<T[]>} 更新后的数据数组
|
|
962
|
+
* @template T
|
|
963
|
+
*/
|
|
964
|
+
)
|
|
965
|
+
}, {
|
|
966
|
+
key: "bulkUpdate",
|
|
967
|
+
value: (function () {
|
|
968
|
+
var _bulkUpdate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(storeName, dataList) {
|
|
969
|
+
var _this10 = this;
|
|
970
|
+
var log,
|
|
971
|
+
storeConfig,
|
|
972
|
+
keyPath,
|
|
973
|
+
memStore,
|
|
974
|
+
uuid,
|
|
975
|
+
_args14 = arguments;
|
|
976
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
977
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
978
|
+
case 0:
|
|
979
|
+
log = _args14.length > 2 && _args14[2] !== undefined ? _args14[2] : false;
|
|
980
|
+
if (!(!dataList || dataList.length === 0)) {
|
|
981
|
+
_context14.next = 3;
|
|
982
|
+
break;
|
|
983
|
+
}
|
|
984
|
+
return _context14.abrupt("return", []);
|
|
985
|
+
case 3:
|
|
986
|
+
if (this.useIndexDB) {
|
|
987
|
+
_context14.next = 9;
|
|
988
|
+
break;
|
|
989
|
+
}
|
|
990
|
+
// 使用内存存储
|
|
991
|
+
storeConfig = this.stores.find(function (s) {
|
|
992
|
+
return s.name === storeName;
|
|
993
|
+
});
|
|
994
|
+
keyPath = (storeConfig === null || storeConfig === void 0 ? void 0 : storeConfig.keyPath) || 'id';
|
|
995
|
+
memStore = this.getMemoryStore(storeName);
|
|
996
|
+
dataList.forEach(function (data) {
|
|
997
|
+
var key = data[keyPath];
|
|
998
|
+
memStore.set(key, data);
|
|
999
|
+
});
|
|
1000
|
+
return _context14.abrupt("return", dataList);
|
|
1001
|
+
case 9:
|
|
1002
|
+
uuid = "[ IndexDB ] BULK_UPDATE: - ".concat(storeName, " - ").concat(dayjs().valueOf());
|
|
1003
|
+
if (log) {
|
|
1004
|
+
this.app.logger.addLog({
|
|
1005
|
+
type: 'info',
|
|
1006
|
+
title: uuid,
|
|
1007
|
+
metadata: {
|
|
1008
|
+
msg: '批量更新数据前',
|
|
1009
|
+
count: dataList.length
|
|
1010
|
+
}
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
return _context14.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
|
|
1014
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
1015
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
1016
|
+
case 0:
|
|
1017
|
+
if (_this10.db) {
|
|
1018
|
+
_context13.next = 3;
|
|
1019
|
+
break;
|
|
1020
|
+
}
|
|
1021
|
+
if (log) {
|
|
1022
|
+
_this10.app.logger.addLog({
|
|
1023
|
+
type: 'error',
|
|
1024
|
+
title: uuid,
|
|
1025
|
+
metadata: {
|
|
1026
|
+
msg: '批量更新数据前 数据库未连接',
|
|
1027
|
+
count: dataList.length
|
|
1028
|
+
}
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
throw new Error('数据库未连接');
|
|
1032
|
+
case 3:
|
|
1033
|
+
_context13.prev = 3;
|
|
1034
|
+
_context13.next = 6;
|
|
1035
|
+
return _this10.db.table(storeName).bulkPut(dataList);
|
|
1036
|
+
case 6:
|
|
1037
|
+
if (log) {
|
|
1038
|
+
_this10.app.logger.addLog({
|
|
1039
|
+
type: 'info',
|
|
1040
|
+
title: uuid,
|
|
1041
|
+
metadata: {
|
|
1042
|
+
msg: '批量更新成功',
|
|
1043
|
+
count: dataList.length
|
|
1044
|
+
}
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
return _context13.abrupt("return", dataList);
|
|
1048
|
+
case 10:
|
|
1049
|
+
_context13.prev = 10;
|
|
1050
|
+
_context13.t0 = _context13["catch"](3);
|
|
1051
|
+
_this10.app.logger.addLog({
|
|
1052
|
+
type: 'error',
|
|
1053
|
+
title: uuid,
|
|
1054
|
+
metadata: {
|
|
1055
|
+
msg: '批量更新数据失败',
|
|
1056
|
+
count: dataList.length,
|
|
1057
|
+
error: _context13.t0.message
|
|
1058
|
+
}
|
|
1059
|
+
});
|
|
1060
|
+
throw new Error(_context13.t0 === null || _context13.t0 === void 0 ? void 0 : _context13.t0.message);
|
|
1061
|
+
case 14:
|
|
1062
|
+
case "end":
|
|
1063
|
+
return _context13.stop();
|
|
1064
|
+
}
|
|
1065
|
+
}, _callee13, null, [[3, 10]]);
|
|
1066
|
+
}))(), "bulkUpdate(".concat(storeName, ")")));
|
|
1067
|
+
case 12:
|
|
1068
|
+
case "end":
|
|
1069
|
+
return _context14.stop();
|
|
1070
|
+
}
|
|
1071
|
+
}, _callee14, this);
|
|
1072
|
+
}));
|
|
1073
|
+
function bulkUpdate(_x11, _x12) {
|
|
1074
|
+
return _bulkUpdate.apply(this, arguments);
|
|
1075
|
+
}
|
|
1076
|
+
return bulkUpdate;
|
|
1077
|
+
}()
|
|
831
1078
|
/**
|
|
832
1079
|
* 更新指定存储对象中的数据
|
|
833
1080
|
* @param {string} storeName - 存储对象名称
|
|
@@ -840,21 +1087,21 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
840
1087
|
}, {
|
|
841
1088
|
key: "update",
|
|
842
1089
|
value: (function () {
|
|
843
|
-
var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
844
|
-
var
|
|
1090
|
+
var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(storeName, data) {
|
|
1091
|
+
var _this11 = this;
|
|
845
1092
|
var log,
|
|
846
1093
|
storeConfig,
|
|
847
1094
|
keyPath,
|
|
848
1095
|
_key3,
|
|
849
1096
|
memStore,
|
|
850
1097
|
uuid,
|
|
851
|
-
|
|
852
|
-
return _regeneratorRuntime().wrap(function
|
|
853
|
-
while (1) switch (
|
|
1098
|
+
_args16 = arguments;
|
|
1099
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1100
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
854
1101
|
case 0:
|
|
855
|
-
log =
|
|
1102
|
+
log = _args16.length > 2 && _args16[2] !== undefined ? _args16[2] : false;
|
|
856
1103
|
if (this.useIndexDB) {
|
|
857
|
-
|
|
1104
|
+
_context16.next = 8;
|
|
858
1105
|
break;
|
|
859
1106
|
}
|
|
860
1107
|
// 使用内存存储
|
|
@@ -864,82 +1111,196 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
864
1111
|
keyPath = (storeConfig === null || storeConfig === void 0 ? void 0 : storeConfig.keyPath) || 'id';
|
|
865
1112
|
_key3 = data[keyPath];
|
|
866
1113
|
memStore = this.getMemoryStore(storeName);
|
|
867
|
-
memStore.set(_key3, data);
|
|
868
|
-
return
|
|
869
|
-
case 8:
|
|
870
|
-
uuid = "[ IndexDB ] UPDATE: - ".concat(storeName, " - ").concat(dayjs().valueOf());
|
|
1114
|
+
memStore.set(_key3, data);
|
|
1115
|
+
return _context16.abrupt("return", data);
|
|
1116
|
+
case 8:
|
|
1117
|
+
uuid = "[ IndexDB ] UPDATE: - ".concat(storeName, " - ").concat(dayjs().valueOf());
|
|
1118
|
+
if (log) {
|
|
1119
|
+
// this.app.logger.addLog({
|
|
1120
|
+
// type: 'info',
|
|
1121
|
+
// title: uuid,
|
|
1122
|
+
// metadata: { msg: '更新数据前', data: data }
|
|
1123
|
+
// })
|
|
1124
|
+
}
|
|
1125
|
+
return _context16.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
|
|
1126
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
1127
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1128
|
+
case 0:
|
|
1129
|
+
if (_this11.db) {
|
|
1130
|
+
_context15.next = 3;
|
|
1131
|
+
break;
|
|
1132
|
+
}
|
|
1133
|
+
if (log) {
|
|
1134
|
+
_this11.app.logger.addLog({
|
|
1135
|
+
type: 'error',
|
|
1136
|
+
title: uuid,
|
|
1137
|
+
metadata: {
|
|
1138
|
+
msg: '数据库未连接'
|
|
1139
|
+
}
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
throw new Error('数据库未连接');
|
|
1143
|
+
case 3:
|
|
1144
|
+
_context15.prev = 3;
|
|
1145
|
+
_context15.next = 6;
|
|
1146
|
+
return _this11.db.table(storeName).put(data);
|
|
1147
|
+
case 6:
|
|
1148
|
+
if (log) {
|
|
1149
|
+
// this.app.logger.addLog({
|
|
1150
|
+
// type: 'info',
|
|
1151
|
+
// title: uuid,
|
|
1152
|
+
// metadata: { msg: '数据更新完成' }
|
|
1153
|
+
// });
|
|
1154
|
+
// console.log('✅ 事务完成');
|
|
1155
|
+
// this.app.logger.addLog({
|
|
1156
|
+
// type: 'info',
|
|
1157
|
+
// title: uuid,
|
|
1158
|
+
// metadata: { msg: '事务完成' }
|
|
1159
|
+
// });
|
|
1160
|
+
}
|
|
1161
|
+
return _context15.abrupt("return", data);
|
|
1162
|
+
case 10:
|
|
1163
|
+
_context15.prev = 10;
|
|
1164
|
+
_context15.t0 = _context15["catch"](3);
|
|
1165
|
+
_this11.app.logger.addLog({
|
|
1166
|
+
type: 'error',
|
|
1167
|
+
title: uuid,
|
|
1168
|
+
metadata: {
|
|
1169
|
+
msg: '数据更新失败',
|
|
1170
|
+
error: _context15.t0.message
|
|
1171
|
+
}
|
|
1172
|
+
});
|
|
1173
|
+
throw new Error(_context15.t0 === null || _context15.t0 === void 0 ? void 0 : _context15.t0.message);
|
|
1174
|
+
case 14:
|
|
1175
|
+
case "end":
|
|
1176
|
+
return _context15.stop();
|
|
1177
|
+
}
|
|
1178
|
+
}, _callee15, null, [[3, 10]]);
|
|
1179
|
+
}))(), "update(".concat(storeName, ")")));
|
|
1180
|
+
case 11:
|
|
1181
|
+
case "end":
|
|
1182
|
+
return _context16.stop();
|
|
1183
|
+
}
|
|
1184
|
+
}, _callee16, this);
|
|
1185
|
+
}));
|
|
1186
|
+
function update(_x13, _x14) {
|
|
1187
|
+
return _update.apply(this, arguments);
|
|
1188
|
+
}
|
|
1189
|
+
return update;
|
|
1190
|
+
}()
|
|
1191
|
+
/**
|
|
1192
|
+
* 批量删除指定存储对象中的数据
|
|
1193
|
+
* @param {string} storeName - 存储对象名称
|
|
1194
|
+
* @param {(string|number)[]} keys - 数据主键数组
|
|
1195
|
+
* @param {boolean} [log=false] - 是否记录日志
|
|
1196
|
+
* @returns {Promise<boolean>} 删除是否成功
|
|
1197
|
+
*/
|
|
1198
|
+
)
|
|
1199
|
+
}, {
|
|
1200
|
+
key: "bulkDelete",
|
|
1201
|
+
value: (function () {
|
|
1202
|
+
var _bulkDelete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(storeName, keys) {
|
|
1203
|
+
var _this12 = this;
|
|
1204
|
+
var log,
|
|
1205
|
+
memStore,
|
|
1206
|
+
uuid,
|
|
1207
|
+
_args18 = arguments;
|
|
1208
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1209
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1210
|
+
case 0:
|
|
1211
|
+
log = _args18.length > 2 && _args18[2] !== undefined ? _args18[2] : false;
|
|
1212
|
+
if (!(!keys || keys.length === 0)) {
|
|
1213
|
+
_context18.next = 3;
|
|
1214
|
+
break;
|
|
1215
|
+
}
|
|
1216
|
+
return _context18.abrupt("return", true);
|
|
1217
|
+
case 3:
|
|
1218
|
+
if (this.useIndexDB) {
|
|
1219
|
+
_context18.next = 7;
|
|
1220
|
+
break;
|
|
1221
|
+
}
|
|
1222
|
+
// 使用内存存储
|
|
1223
|
+
memStore = this.getMemoryStore(storeName);
|
|
1224
|
+
keys.forEach(function (key) {
|
|
1225
|
+
return memStore.delete(key);
|
|
1226
|
+
});
|
|
1227
|
+
return _context18.abrupt("return", true);
|
|
1228
|
+
case 7:
|
|
1229
|
+
uuid = "[ IndexDB ] BULK_DELETE: - ".concat(storeName, " - ").concat(dayjs().valueOf());
|
|
871
1230
|
if (log) {
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
1231
|
+
this.app.logger.addLog({
|
|
1232
|
+
type: 'info',
|
|
1233
|
+
title: uuid,
|
|
1234
|
+
metadata: {
|
|
1235
|
+
msg: '批量删除数据前',
|
|
1236
|
+
count: keys.length
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
877
1239
|
}
|
|
878
|
-
return
|
|
879
|
-
return _regeneratorRuntime().wrap(function
|
|
880
|
-
while (1) switch (
|
|
1240
|
+
return _context18.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
|
|
1241
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1242
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
881
1243
|
case 0:
|
|
882
|
-
if (
|
|
883
|
-
|
|
1244
|
+
if (_this12.db) {
|
|
1245
|
+
_context17.next = 3;
|
|
884
1246
|
break;
|
|
885
1247
|
}
|
|
886
1248
|
if (log) {
|
|
887
|
-
|
|
1249
|
+
_this12.app.logger.addLog({
|
|
888
1250
|
type: 'error',
|
|
889
1251
|
title: uuid,
|
|
890
1252
|
metadata: {
|
|
891
|
-
msg: '数据库未连接'
|
|
1253
|
+
msg: '批量删除数据前 数据库未连接',
|
|
1254
|
+
count: keys.length
|
|
892
1255
|
}
|
|
893
1256
|
});
|
|
894
1257
|
}
|
|
895
1258
|
throw new Error('数据库未连接');
|
|
896
1259
|
case 3:
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
return
|
|
1260
|
+
_context17.prev = 3;
|
|
1261
|
+
_context17.next = 6;
|
|
1262
|
+
return _this12.db.table(storeName).bulkDelete(keys);
|
|
900
1263
|
case 6:
|
|
901
1264
|
if (log) {
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
// title: uuid,
|
|
911
|
-
// metadata: { msg: '事务完成' }
|
|
912
|
-
// });
|
|
1265
|
+
_this12.app.logger.addLog({
|
|
1266
|
+
type: 'info',
|
|
1267
|
+
title: uuid,
|
|
1268
|
+
metadata: {
|
|
1269
|
+
msg: '批量删除成功',
|
|
1270
|
+
count: keys.length
|
|
1271
|
+
}
|
|
1272
|
+
});
|
|
913
1273
|
}
|
|
914
|
-
return
|
|
1274
|
+
return _context17.abrupt("return", true);
|
|
915
1275
|
case 10:
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
1276
|
+
_context17.prev = 10;
|
|
1277
|
+
_context17.t0 = _context17["catch"](3);
|
|
1278
|
+
_this12.app.logger.addLog({
|
|
919
1279
|
type: 'error',
|
|
920
1280
|
title: uuid,
|
|
921
1281
|
metadata: {
|
|
922
|
-
msg: '
|
|
923
|
-
|
|
1282
|
+
msg: '批量删除数据失败',
|
|
1283
|
+
count: keys.length,
|
|
1284
|
+
error: _context17.t0.message
|
|
924
1285
|
}
|
|
925
1286
|
});
|
|
926
|
-
throw new Error(
|
|
1287
|
+
throw new Error(_context17.t0 === null || _context17.t0 === void 0 ? void 0 : _context17.t0.message);
|
|
927
1288
|
case 14:
|
|
928
1289
|
case "end":
|
|
929
|
-
return
|
|
1290
|
+
return _context17.stop();
|
|
930
1291
|
}
|
|
931
|
-
},
|
|
932
|
-
}))(), "
|
|
933
|
-
case
|
|
1292
|
+
}, _callee17, null, [[3, 10]]);
|
|
1293
|
+
}))(), "bulkDelete(".concat(storeName, ")")));
|
|
1294
|
+
case 10:
|
|
934
1295
|
case "end":
|
|
935
|
-
return
|
|
1296
|
+
return _context18.stop();
|
|
936
1297
|
}
|
|
937
|
-
},
|
|
1298
|
+
}, _callee18, this);
|
|
938
1299
|
}));
|
|
939
|
-
function
|
|
940
|
-
return
|
|
1300
|
+
function bulkDelete(_x15, _x16) {
|
|
1301
|
+
return _bulkDelete.apply(this, arguments);
|
|
941
1302
|
}
|
|
942
|
-
return
|
|
1303
|
+
return bulkDelete;
|
|
943
1304
|
}()
|
|
944
1305
|
/**
|
|
945
1306
|
* 删除指定存储对象中的数据
|
|
@@ -951,52 +1312,52 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
951
1312
|
}, {
|
|
952
1313
|
key: "delete",
|
|
953
1314
|
value: (function () {
|
|
954
|
-
var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
955
|
-
var
|
|
1315
|
+
var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(storeName, key) {
|
|
1316
|
+
var _this13 = this;
|
|
956
1317
|
var memStore;
|
|
957
|
-
return _regeneratorRuntime().wrap(function
|
|
958
|
-
while (1) switch (
|
|
1318
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1319
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
959
1320
|
case 0:
|
|
960
1321
|
if (this.useIndexDB) {
|
|
961
|
-
|
|
1322
|
+
_context20.next = 3;
|
|
962
1323
|
break;
|
|
963
1324
|
}
|
|
964
1325
|
// 使用内存存储
|
|
965
1326
|
memStore = this.getMemoryStore(storeName);
|
|
966
|
-
return
|
|
1327
|
+
return _context20.abrupt("return", memStore.delete(key));
|
|
967
1328
|
case 3:
|
|
968
|
-
return
|
|
969
|
-
return _regeneratorRuntime().wrap(function
|
|
970
|
-
while (1) switch (
|
|
1329
|
+
return _context20.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
|
|
1330
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
1331
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
971
1332
|
case 0:
|
|
972
|
-
if (
|
|
973
|
-
|
|
1333
|
+
if (_this13.db) {
|
|
1334
|
+
_context19.next = 2;
|
|
974
1335
|
break;
|
|
975
1336
|
}
|
|
976
1337
|
throw new Error('数据库未连接');
|
|
977
1338
|
case 2:
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
return
|
|
1339
|
+
_context19.prev = 2;
|
|
1340
|
+
_context19.next = 5;
|
|
1341
|
+
return _this13.db.table(storeName).delete(key);
|
|
981
1342
|
case 5:
|
|
982
|
-
return
|
|
1343
|
+
return _context19.abrupt("return", true);
|
|
983
1344
|
case 8:
|
|
984
|
-
|
|
985
|
-
|
|
1345
|
+
_context19.prev = 8;
|
|
1346
|
+
_context19.t0 = _context19["catch"](2);
|
|
986
1347
|
throw new Error('删除数据失败');
|
|
987
1348
|
case 11:
|
|
988
1349
|
case "end":
|
|
989
|
-
return
|
|
1350
|
+
return _context19.stop();
|
|
990
1351
|
}
|
|
991
|
-
},
|
|
1352
|
+
}, _callee19, null, [[2, 8]]);
|
|
992
1353
|
}))(), "delete(".concat(storeName, ")")));
|
|
993
1354
|
case 4:
|
|
994
1355
|
case "end":
|
|
995
|
-
return
|
|
1356
|
+
return _context20.stop();
|
|
996
1357
|
}
|
|
997
|
-
},
|
|
1358
|
+
}, _callee20, this);
|
|
998
1359
|
}));
|
|
999
|
-
function _delete(
|
|
1360
|
+
function _delete(_x17, _x18) {
|
|
1000
1361
|
return _delete2.apply(this, arguments);
|
|
1001
1362
|
}
|
|
1002
1363
|
return _delete;
|
|
@@ -1013,20 +1374,20 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1013
1374
|
}, {
|
|
1014
1375
|
key: "getByIndex",
|
|
1015
1376
|
value: (function () {
|
|
1016
|
-
var _getByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1017
|
-
var
|
|
1377
|
+
var _getByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(storeName, indexName, indexValue) {
|
|
1378
|
+
var _this14 = this;
|
|
1018
1379
|
var _storeConfig$indexes, allData, storeConfig, index;
|
|
1019
|
-
return _regeneratorRuntime().wrap(function
|
|
1020
|
-
while (1) switch (
|
|
1380
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
1381
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1021
1382
|
case 0:
|
|
1022
1383
|
if (this.useIndexDB) {
|
|
1023
|
-
|
|
1384
|
+
_context22.next = 9;
|
|
1024
1385
|
break;
|
|
1025
1386
|
}
|
|
1026
|
-
|
|
1387
|
+
_context22.next = 3;
|
|
1027
1388
|
return this.getAll(storeName);
|
|
1028
1389
|
case 3:
|
|
1029
|
-
allData =
|
|
1390
|
+
allData = _context22.sent;
|
|
1030
1391
|
storeConfig = this.stores.find(function (s) {
|
|
1031
1392
|
return s.name === storeName;
|
|
1032
1393
|
});
|
|
@@ -1034,49 +1395,49 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1034
1395
|
return i.name === indexName;
|
|
1035
1396
|
});
|
|
1036
1397
|
if (index) {
|
|
1037
|
-
|
|
1398
|
+
_context22.next = 8;
|
|
1038
1399
|
break;
|
|
1039
1400
|
}
|
|
1040
|
-
return
|
|
1401
|
+
return _context22.abrupt("return", null);
|
|
1041
1402
|
case 8:
|
|
1042
|
-
return
|
|
1403
|
+
return _context22.abrupt("return", allData.find(function (item) {
|
|
1043
1404
|
return item[index.keyPath] === indexValue;
|
|
1044
1405
|
}) || null);
|
|
1045
1406
|
case 9:
|
|
1046
|
-
return
|
|
1407
|
+
return _context22.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
|
|
1047
1408
|
var result;
|
|
1048
|
-
return _regeneratorRuntime().wrap(function
|
|
1049
|
-
while (1) switch (
|
|
1409
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1410
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
1050
1411
|
case 0:
|
|
1051
|
-
if (
|
|
1052
|
-
|
|
1412
|
+
if (_this14.db) {
|
|
1413
|
+
_context21.next = 2;
|
|
1053
1414
|
break;
|
|
1054
1415
|
}
|
|
1055
1416
|
throw new Error('数据库未连接');
|
|
1056
1417
|
case 2:
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
return
|
|
1418
|
+
_context21.prev = 2;
|
|
1419
|
+
_context21.next = 5;
|
|
1420
|
+
return _this14.db.table(storeName).where(indexName).equals(indexValue).first();
|
|
1060
1421
|
case 5:
|
|
1061
|
-
result =
|
|
1062
|
-
return
|
|
1422
|
+
result = _context21.sent;
|
|
1423
|
+
return _context21.abrupt("return", result || null);
|
|
1063
1424
|
case 9:
|
|
1064
|
-
|
|
1065
|
-
|
|
1425
|
+
_context21.prev = 9;
|
|
1426
|
+
_context21.t0 = _context21["catch"](2);
|
|
1066
1427
|
throw new Error('通过索引获取数据失败');
|
|
1067
1428
|
case 12:
|
|
1068
1429
|
case "end":
|
|
1069
|
-
return
|
|
1430
|
+
return _context21.stop();
|
|
1070
1431
|
}
|
|
1071
|
-
},
|
|
1432
|
+
}, _callee21, null, [[2, 9]]);
|
|
1072
1433
|
}))(), "getByIndex(".concat(storeName, ", ").concat(indexName, ")")));
|
|
1073
1434
|
case 10:
|
|
1074
1435
|
case "end":
|
|
1075
|
-
return
|
|
1436
|
+
return _context22.stop();
|
|
1076
1437
|
}
|
|
1077
|
-
},
|
|
1438
|
+
}, _callee22, this);
|
|
1078
1439
|
}));
|
|
1079
|
-
function getByIndex(
|
|
1440
|
+
function getByIndex(_x19, _x20, _x21) {
|
|
1080
1441
|
return _getByIndex.apply(this, arguments);
|
|
1081
1442
|
}
|
|
1082
1443
|
return getByIndex;
|
|
@@ -1092,20 +1453,20 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1092
1453
|
}, {
|
|
1093
1454
|
key: "existsByIndex",
|
|
1094
1455
|
value: (function () {
|
|
1095
|
-
var _existsByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1096
|
-
var
|
|
1456
|
+
var _existsByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(storeName, indexName, indexValue) {
|
|
1457
|
+
var _this15 = this;
|
|
1097
1458
|
var _storeConfig$indexes2, allData, storeConfig, index;
|
|
1098
|
-
return _regeneratorRuntime().wrap(function
|
|
1099
|
-
while (1) switch (
|
|
1459
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
1460
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
1100
1461
|
case 0:
|
|
1101
1462
|
if (this.useIndexDB) {
|
|
1102
|
-
|
|
1463
|
+
_context24.next = 9;
|
|
1103
1464
|
break;
|
|
1104
1465
|
}
|
|
1105
|
-
|
|
1466
|
+
_context24.next = 3;
|
|
1106
1467
|
return this.getAll(storeName);
|
|
1107
1468
|
case 3:
|
|
1108
|
-
allData =
|
|
1469
|
+
allData = _context24.sent;
|
|
1109
1470
|
storeConfig = this.stores.find(function (s) {
|
|
1110
1471
|
return s.name === storeName;
|
|
1111
1472
|
});
|
|
@@ -1113,49 +1474,49 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1113
1474
|
return i.name === indexName;
|
|
1114
1475
|
});
|
|
1115
1476
|
if (index) {
|
|
1116
|
-
|
|
1477
|
+
_context24.next = 8;
|
|
1117
1478
|
break;
|
|
1118
1479
|
}
|
|
1119
|
-
return
|
|
1480
|
+
return _context24.abrupt("return", false);
|
|
1120
1481
|
case 8:
|
|
1121
|
-
return
|
|
1482
|
+
return _context24.abrupt("return", allData.some(function (item) {
|
|
1122
1483
|
return item[index.keyPath] === indexValue;
|
|
1123
1484
|
}));
|
|
1124
1485
|
case 9:
|
|
1125
|
-
return
|
|
1486
|
+
return _context24.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
|
|
1126
1487
|
var count;
|
|
1127
|
-
return _regeneratorRuntime().wrap(function
|
|
1128
|
-
while (1) switch (
|
|
1488
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
1489
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
1129
1490
|
case 0:
|
|
1130
|
-
if (
|
|
1131
|
-
|
|
1491
|
+
if (_this15.db) {
|
|
1492
|
+
_context23.next = 2;
|
|
1132
1493
|
break;
|
|
1133
1494
|
}
|
|
1134
1495
|
throw new Error('数据库未连接');
|
|
1135
1496
|
case 2:
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
return
|
|
1497
|
+
_context23.prev = 2;
|
|
1498
|
+
_context23.next = 5;
|
|
1499
|
+
return _this15.db.table(storeName).where(indexName).equals(indexValue).count();
|
|
1139
1500
|
case 5:
|
|
1140
|
-
count =
|
|
1141
|
-
return
|
|
1501
|
+
count = _context23.sent;
|
|
1502
|
+
return _context23.abrupt("return", count > 0);
|
|
1142
1503
|
case 9:
|
|
1143
|
-
|
|
1144
|
-
|
|
1504
|
+
_context23.prev = 9;
|
|
1505
|
+
_context23.t0 = _context23["catch"](2);
|
|
1145
1506
|
throw new Error('通过索引检查数据存在性失败');
|
|
1146
1507
|
case 12:
|
|
1147
1508
|
case "end":
|
|
1148
|
-
return
|
|
1509
|
+
return _context23.stop();
|
|
1149
1510
|
}
|
|
1150
|
-
},
|
|
1511
|
+
}, _callee23, null, [[2, 9]]);
|
|
1151
1512
|
}))(), "existsByIndex(".concat(storeName, ", ").concat(indexName, ")")));
|
|
1152
1513
|
case 10:
|
|
1153
1514
|
case "end":
|
|
1154
|
-
return
|
|
1515
|
+
return _context24.stop();
|
|
1155
1516
|
}
|
|
1156
|
-
},
|
|
1517
|
+
}, _callee24, this);
|
|
1157
1518
|
}));
|
|
1158
|
-
function existsByIndex(
|
|
1519
|
+
function existsByIndex(_x22, _x23, _x24) {
|
|
1159
1520
|
return _existsByIndex.apply(this, arguments);
|
|
1160
1521
|
}
|
|
1161
1522
|
return existsByIndex;
|
|
@@ -1172,20 +1533,20 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1172
1533
|
}, {
|
|
1173
1534
|
key: "getAllByIndex",
|
|
1174
1535
|
value: (function () {
|
|
1175
|
-
var _getAllByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1176
|
-
var
|
|
1536
|
+
var _getAllByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(storeName, indexName, indexValue) {
|
|
1537
|
+
var _this16 = this;
|
|
1177
1538
|
var _storeConfig$indexes3, allData, storeConfig, index;
|
|
1178
|
-
return _regeneratorRuntime().wrap(function
|
|
1179
|
-
while (1) switch (
|
|
1539
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
1540
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
1180
1541
|
case 0:
|
|
1181
1542
|
if (this.useIndexDB) {
|
|
1182
|
-
|
|
1543
|
+
_context26.next = 9;
|
|
1183
1544
|
break;
|
|
1184
1545
|
}
|
|
1185
|
-
|
|
1546
|
+
_context26.next = 3;
|
|
1186
1547
|
return this.getAll(storeName);
|
|
1187
1548
|
case 3:
|
|
1188
|
-
allData =
|
|
1549
|
+
allData = _context26.sent;
|
|
1189
1550
|
storeConfig = this.stores.find(function (s) {
|
|
1190
1551
|
return s.name === storeName;
|
|
1191
1552
|
});
|
|
@@ -1193,49 +1554,49 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1193
1554
|
return i.name === indexName;
|
|
1194
1555
|
});
|
|
1195
1556
|
if (index) {
|
|
1196
|
-
|
|
1557
|
+
_context26.next = 8;
|
|
1197
1558
|
break;
|
|
1198
1559
|
}
|
|
1199
|
-
return
|
|
1560
|
+
return _context26.abrupt("return", []);
|
|
1200
1561
|
case 8:
|
|
1201
|
-
return
|
|
1562
|
+
return _context26.abrupt("return", allData.filter(function (item) {
|
|
1202
1563
|
return item[index.keyPath] === indexValue;
|
|
1203
1564
|
}));
|
|
1204
1565
|
case 9:
|
|
1205
|
-
return
|
|
1566
|
+
return _context26.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
|
|
1206
1567
|
var results;
|
|
1207
|
-
return _regeneratorRuntime().wrap(function
|
|
1208
|
-
while (1) switch (
|
|
1568
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
1569
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
1209
1570
|
case 0:
|
|
1210
|
-
if (
|
|
1211
|
-
|
|
1571
|
+
if (_this16.db) {
|
|
1572
|
+
_context25.next = 2;
|
|
1212
1573
|
break;
|
|
1213
1574
|
}
|
|
1214
1575
|
throw new Error('数据库未连接');
|
|
1215
1576
|
case 2:
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
return
|
|
1577
|
+
_context25.prev = 2;
|
|
1578
|
+
_context25.next = 5;
|
|
1579
|
+
return _this16.db.table(storeName).where(indexName).equals(indexValue).toArray();
|
|
1219
1580
|
case 5:
|
|
1220
|
-
results =
|
|
1221
|
-
return
|
|
1581
|
+
results = _context25.sent;
|
|
1582
|
+
return _context25.abrupt("return", results);
|
|
1222
1583
|
case 9:
|
|
1223
|
-
|
|
1224
|
-
|
|
1584
|
+
_context25.prev = 9;
|
|
1585
|
+
_context25.t0 = _context25["catch"](2);
|
|
1225
1586
|
throw new Error('通过索引获取多条数据失败');
|
|
1226
1587
|
case 12:
|
|
1227
1588
|
case "end":
|
|
1228
|
-
return
|
|
1589
|
+
return _context25.stop();
|
|
1229
1590
|
}
|
|
1230
|
-
},
|
|
1591
|
+
}, _callee25, null, [[2, 9]]);
|
|
1231
1592
|
}))(), "getAllByIndex(".concat(storeName, ", ").concat(indexName, ")")));
|
|
1232
1593
|
case 10:
|
|
1233
1594
|
case "end":
|
|
1234
|
-
return
|
|
1595
|
+
return _context26.stop();
|
|
1235
1596
|
}
|
|
1236
|
-
},
|
|
1597
|
+
}, _callee26, this);
|
|
1237
1598
|
}));
|
|
1238
|
-
function getAllByIndex(
|
|
1599
|
+
function getAllByIndex(_x25, _x26, _x27) {
|
|
1239
1600
|
return _getAllByIndex.apply(this, arguments);
|
|
1240
1601
|
}
|
|
1241
1602
|
return getAllByIndex;
|
|
@@ -1249,56 +1610,56 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1249
1610
|
}, {
|
|
1250
1611
|
key: "count",
|
|
1251
1612
|
value: (function () {
|
|
1252
|
-
var _count = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1253
|
-
var
|
|
1613
|
+
var _count = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(storeName) {
|
|
1614
|
+
var _this17 = this;
|
|
1254
1615
|
var allData;
|
|
1255
|
-
return _regeneratorRuntime().wrap(function
|
|
1256
|
-
while (1) switch (
|
|
1616
|
+
return _regeneratorRuntime().wrap(function _callee28$(_context28) {
|
|
1617
|
+
while (1) switch (_context28.prev = _context28.next) {
|
|
1257
1618
|
case 0:
|
|
1258
1619
|
if (this.useIndexDB) {
|
|
1259
|
-
|
|
1620
|
+
_context28.next = 5;
|
|
1260
1621
|
break;
|
|
1261
1622
|
}
|
|
1262
|
-
|
|
1623
|
+
_context28.next = 3;
|
|
1263
1624
|
return this.getAll(storeName);
|
|
1264
1625
|
case 3:
|
|
1265
|
-
allData =
|
|
1266
|
-
return
|
|
1626
|
+
allData = _context28.sent;
|
|
1627
|
+
return _context28.abrupt("return", allData.length);
|
|
1267
1628
|
case 5:
|
|
1268
|
-
return
|
|
1629
|
+
return _context28.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
|
|
1269
1630
|
var _count2;
|
|
1270
|
-
return _regeneratorRuntime().wrap(function
|
|
1271
|
-
while (1) switch (
|
|
1631
|
+
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
1632
|
+
while (1) switch (_context27.prev = _context27.next) {
|
|
1272
1633
|
case 0:
|
|
1273
|
-
if (
|
|
1274
|
-
|
|
1634
|
+
if (_this17.db) {
|
|
1635
|
+
_context27.next = 2;
|
|
1275
1636
|
break;
|
|
1276
1637
|
}
|
|
1277
1638
|
throw new Error('数据库未连接');
|
|
1278
1639
|
case 2:
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
return
|
|
1640
|
+
_context27.prev = 2;
|
|
1641
|
+
_context27.next = 5;
|
|
1642
|
+
return _this17.db.table(storeName).count();
|
|
1282
1643
|
case 5:
|
|
1283
|
-
_count2 =
|
|
1284
|
-
return
|
|
1644
|
+
_count2 = _context27.sent;
|
|
1645
|
+
return _context27.abrupt("return", _count2);
|
|
1285
1646
|
case 9:
|
|
1286
|
-
|
|
1287
|
-
|
|
1647
|
+
_context27.prev = 9;
|
|
1648
|
+
_context27.t0 = _context27["catch"](2);
|
|
1288
1649
|
throw new Error('统计数据数量失败');
|
|
1289
1650
|
case 12:
|
|
1290
1651
|
case "end":
|
|
1291
|
-
return
|
|
1652
|
+
return _context27.stop();
|
|
1292
1653
|
}
|
|
1293
|
-
},
|
|
1654
|
+
}, _callee27, null, [[2, 9]]);
|
|
1294
1655
|
}))(), "count(".concat(storeName, ")")));
|
|
1295
1656
|
case 6:
|
|
1296
1657
|
case "end":
|
|
1297
|
-
return
|
|
1658
|
+
return _context28.stop();
|
|
1298
1659
|
}
|
|
1299
|
-
},
|
|
1660
|
+
}, _callee28, this);
|
|
1300
1661
|
}));
|
|
1301
|
-
function count(
|
|
1662
|
+
function count(_x28) {
|
|
1302
1663
|
return _count.apply(this, arguments);
|
|
1303
1664
|
}
|
|
1304
1665
|
return count;
|
|
@@ -1314,56 +1675,56 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1314
1675
|
}, {
|
|
1315
1676
|
key: "countByIndex",
|
|
1316
1677
|
value: (function () {
|
|
1317
|
-
var _countByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1318
|
-
var
|
|
1678
|
+
var _countByIndex = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(storeName, indexName, indexValue) {
|
|
1679
|
+
var _this18 = this;
|
|
1319
1680
|
var matchingData;
|
|
1320
|
-
return _regeneratorRuntime().wrap(function
|
|
1321
|
-
while (1) switch (
|
|
1681
|
+
return _regeneratorRuntime().wrap(function _callee30$(_context30) {
|
|
1682
|
+
while (1) switch (_context30.prev = _context30.next) {
|
|
1322
1683
|
case 0:
|
|
1323
1684
|
if (this.useIndexDB) {
|
|
1324
|
-
|
|
1685
|
+
_context30.next = 5;
|
|
1325
1686
|
break;
|
|
1326
1687
|
}
|
|
1327
|
-
|
|
1688
|
+
_context30.next = 3;
|
|
1328
1689
|
return this.getAllByIndex(storeName, indexName, indexValue);
|
|
1329
1690
|
case 3:
|
|
1330
|
-
matchingData =
|
|
1331
|
-
return
|
|
1691
|
+
matchingData = _context30.sent;
|
|
1692
|
+
return _context30.abrupt("return", matchingData.length);
|
|
1332
1693
|
case 5:
|
|
1333
|
-
return
|
|
1694
|
+
return _context30.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
|
|
1334
1695
|
var count;
|
|
1335
|
-
return _regeneratorRuntime().wrap(function
|
|
1336
|
-
while (1) switch (
|
|
1696
|
+
return _regeneratorRuntime().wrap(function _callee29$(_context29) {
|
|
1697
|
+
while (1) switch (_context29.prev = _context29.next) {
|
|
1337
1698
|
case 0:
|
|
1338
|
-
if (
|
|
1339
|
-
|
|
1699
|
+
if (_this18.db) {
|
|
1700
|
+
_context29.next = 2;
|
|
1340
1701
|
break;
|
|
1341
1702
|
}
|
|
1342
1703
|
throw new Error('数据库未连接');
|
|
1343
1704
|
case 2:
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
return
|
|
1705
|
+
_context29.prev = 2;
|
|
1706
|
+
_context29.next = 5;
|
|
1707
|
+
return _this18.db.table(storeName).where(indexName).equals(indexValue).count();
|
|
1347
1708
|
case 5:
|
|
1348
|
-
count =
|
|
1349
|
-
return
|
|
1709
|
+
count = _context29.sent;
|
|
1710
|
+
return _context29.abrupt("return", count);
|
|
1350
1711
|
case 9:
|
|
1351
|
-
|
|
1352
|
-
|
|
1712
|
+
_context29.prev = 9;
|
|
1713
|
+
_context29.t0 = _context29["catch"](2);
|
|
1353
1714
|
throw new Error('通过索引统计数据数量失败');
|
|
1354
1715
|
case 12:
|
|
1355
1716
|
case "end":
|
|
1356
|
-
return
|
|
1717
|
+
return _context29.stop();
|
|
1357
1718
|
}
|
|
1358
|
-
},
|
|
1719
|
+
}, _callee29, null, [[2, 9]]);
|
|
1359
1720
|
}))(), "countByIndex(".concat(storeName, ", ").concat(indexName, ")")));
|
|
1360
1721
|
case 6:
|
|
1361
1722
|
case "end":
|
|
1362
|
-
return
|
|
1723
|
+
return _context30.stop();
|
|
1363
1724
|
}
|
|
1364
|
-
},
|
|
1725
|
+
}, _callee30, this);
|
|
1365
1726
|
}));
|
|
1366
|
-
function countByIndex(
|
|
1727
|
+
function countByIndex(_x29, _x30, _x31) {
|
|
1367
1728
|
return _countByIndex.apply(this, arguments);
|
|
1368
1729
|
}
|
|
1369
1730
|
return countByIndex;
|
|
@@ -1378,62 +1739,62 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1378
1739
|
}, {
|
|
1379
1740
|
key: "getAll",
|
|
1380
1741
|
value: (function () {
|
|
1381
|
-
var _getAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1382
|
-
var
|
|
1742
|
+
var _getAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(storeName) {
|
|
1743
|
+
var _this19 = this;
|
|
1383
1744
|
var memStore;
|
|
1384
|
-
return _regeneratorRuntime().wrap(function
|
|
1385
|
-
while (1) switch (
|
|
1745
|
+
return _regeneratorRuntime().wrap(function _callee32$(_context32) {
|
|
1746
|
+
while (1) switch (_context32.prev = _context32.next) {
|
|
1386
1747
|
case 0:
|
|
1387
1748
|
if (this.useIndexDB) {
|
|
1388
|
-
|
|
1749
|
+
_context32.next = 3;
|
|
1389
1750
|
break;
|
|
1390
1751
|
}
|
|
1391
1752
|
// 使用内存存储
|
|
1392
1753
|
memStore = this.getMemoryStore(storeName);
|
|
1393
|
-
return
|
|
1754
|
+
return _context32.abrupt("return", Array.from(memStore.values()));
|
|
1394
1755
|
case 3:
|
|
1395
|
-
return
|
|
1756
|
+
return _context32.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31() {
|
|
1396
1757
|
var results;
|
|
1397
|
-
return _regeneratorRuntime().wrap(function
|
|
1398
|
-
while (1) switch (
|
|
1758
|
+
return _regeneratorRuntime().wrap(function _callee31$(_context31) {
|
|
1759
|
+
while (1) switch (_context31.prev = _context31.next) {
|
|
1399
1760
|
case 0:
|
|
1400
|
-
if (
|
|
1401
|
-
|
|
1761
|
+
if (_this19.db) {
|
|
1762
|
+
_context31.next = 2;
|
|
1402
1763
|
break;
|
|
1403
1764
|
}
|
|
1404
1765
|
throw new Error('数据库未连接');
|
|
1405
1766
|
case 2:
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
return
|
|
1767
|
+
_context31.prev = 2;
|
|
1768
|
+
_context31.next = 5;
|
|
1769
|
+
return _this19.db.table(storeName).toArray();
|
|
1409
1770
|
case 5:
|
|
1410
|
-
results =
|
|
1411
|
-
return
|
|
1771
|
+
results = _context31.sent;
|
|
1772
|
+
return _context31.abrupt("return", results);
|
|
1412
1773
|
case 9:
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1774
|
+
_context31.prev = 9;
|
|
1775
|
+
_context31.t0 = _context31["catch"](2);
|
|
1776
|
+
_this19.app.logger.addLog({
|
|
1416
1777
|
type: 'error',
|
|
1417
1778
|
title: "[ IndexDB ] ERROR: - getAll(".concat(storeName, ")"),
|
|
1418
1779
|
metadata: {
|
|
1419
1780
|
msg: '获取所有数据失败',
|
|
1420
|
-
error:
|
|
1781
|
+
error: _context31.t0.message
|
|
1421
1782
|
}
|
|
1422
1783
|
});
|
|
1423
|
-
throw new Error(
|
|
1784
|
+
throw new Error(_context31.t0 === null || _context31.t0 === void 0 ? void 0 : _context31.t0.message);
|
|
1424
1785
|
case 13:
|
|
1425
1786
|
case "end":
|
|
1426
|
-
return
|
|
1787
|
+
return _context31.stop();
|
|
1427
1788
|
}
|
|
1428
|
-
},
|
|
1789
|
+
}, _callee31, null, [[2, 9]]);
|
|
1429
1790
|
}))(), "getAll(".concat(storeName, ")")));
|
|
1430
1791
|
case 4:
|
|
1431
1792
|
case "end":
|
|
1432
|
-
return
|
|
1793
|
+
return _context32.stop();
|
|
1433
1794
|
}
|
|
1434
|
-
},
|
|
1795
|
+
}, _callee32, this);
|
|
1435
1796
|
}));
|
|
1436
|
-
function getAll(
|
|
1797
|
+
function getAll(_x32) {
|
|
1437
1798
|
return _getAll.apply(this, arguments);
|
|
1438
1799
|
}
|
|
1439
1800
|
return getAll;
|
|
@@ -1447,53 +1808,53 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1447
1808
|
}, {
|
|
1448
1809
|
key: "clear",
|
|
1449
1810
|
value: (function () {
|
|
1450
|
-
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1451
|
-
var
|
|
1811
|
+
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(storeName) {
|
|
1812
|
+
var _this20 = this;
|
|
1452
1813
|
var memStore;
|
|
1453
|
-
return _regeneratorRuntime().wrap(function
|
|
1454
|
-
while (1) switch (
|
|
1814
|
+
return _regeneratorRuntime().wrap(function _callee34$(_context34) {
|
|
1815
|
+
while (1) switch (_context34.prev = _context34.next) {
|
|
1455
1816
|
case 0:
|
|
1456
1817
|
if (this.useIndexDB) {
|
|
1457
|
-
|
|
1818
|
+
_context34.next = 4;
|
|
1458
1819
|
break;
|
|
1459
1820
|
}
|
|
1460
1821
|
// 使用内存存储
|
|
1461
1822
|
memStore = this.getMemoryStore(storeName);
|
|
1462
1823
|
memStore.clear();
|
|
1463
|
-
return
|
|
1824
|
+
return _context34.abrupt("return", true);
|
|
1464
1825
|
case 4:
|
|
1465
|
-
return
|
|
1466
|
-
return _regeneratorRuntime().wrap(function
|
|
1467
|
-
while (1) switch (
|
|
1826
|
+
return _context34.abrupt("return", this.withTimeout(_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33() {
|
|
1827
|
+
return _regeneratorRuntime().wrap(function _callee33$(_context33) {
|
|
1828
|
+
while (1) switch (_context33.prev = _context33.next) {
|
|
1468
1829
|
case 0:
|
|
1469
|
-
if (
|
|
1470
|
-
|
|
1830
|
+
if (_this20.db) {
|
|
1831
|
+
_context33.next = 2;
|
|
1471
1832
|
break;
|
|
1472
1833
|
}
|
|
1473
1834
|
throw new Error('数据库未连接');
|
|
1474
1835
|
case 2:
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
return
|
|
1836
|
+
_context33.prev = 2;
|
|
1837
|
+
_context33.next = 5;
|
|
1838
|
+
return _this20.db.table(storeName).clear();
|
|
1478
1839
|
case 5:
|
|
1479
|
-
return
|
|
1840
|
+
return _context33.abrupt("return", true);
|
|
1480
1841
|
case 8:
|
|
1481
|
-
|
|
1482
|
-
|
|
1842
|
+
_context33.prev = 8;
|
|
1843
|
+
_context33.t0 = _context33["catch"](2);
|
|
1483
1844
|
throw new Error('清空数据失败');
|
|
1484
1845
|
case 11:
|
|
1485
1846
|
case "end":
|
|
1486
|
-
return
|
|
1847
|
+
return _context33.stop();
|
|
1487
1848
|
}
|
|
1488
|
-
},
|
|
1849
|
+
}, _callee33, null, [[2, 8]]);
|
|
1489
1850
|
}))(), "clear(".concat(storeName, ")")));
|
|
1490
1851
|
case 5:
|
|
1491
1852
|
case "end":
|
|
1492
|
-
return
|
|
1853
|
+
return _context34.stop();
|
|
1493
1854
|
}
|
|
1494
|
-
},
|
|
1855
|
+
}, _callee34, this);
|
|
1495
1856
|
}));
|
|
1496
|
-
function clear(
|
|
1857
|
+
function clear(_x33) {
|
|
1497
1858
|
return _clear.apply(this, arguments);
|
|
1498
1859
|
}
|
|
1499
1860
|
return clear;
|
|
@@ -1566,6 +1927,14 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1566
1927
|
* const user = { id: '1', name: '张三', email: 'zhangsan@example.com', department: 'IT' };
|
|
1567
1928
|
* await db.add('users', user);
|
|
1568
1929
|
*
|
|
1930
|
+
* // 3.1 批量添加数据
|
|
1931
|
+
* const users = [
|
|
1932
|
+
* { id: '2', name: '李四', email: 'lisi@example.com', department: 'IT' },
|
|
1933
|
+
* { id: '3', name: '王五', email: 'wangwu@example.com', department: 'HR' },
|
|
1934
|
+
* { id: '4', name: '赵六', email: 'zhaoliu@example.com', department: 'IT' }
|
|
1935
|
+
* ];
|
|
1936
|
+
* await db.bulkAdd('users', users);
|
|
1937
|
+
*
|
|
1569
1938
|
* // 4. 获取数据
|
|
1570
1939
|
* const retrievedUser = await db.get('users', '1');
|
|
1571
1940
|
*
|
|
@@ -1589,12 +1958,22 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1589
1958
|
* user.name = '张三 (已更新)';
|
|
1590
1959
|
* await db.update('users', user);
|
|
1591
1960
|
*
|
|
1961
|
+
* // 10.1 批量更新数据
|
|
1962
|
+
* const updatedUsers = [
|
|
1963
|
+
* { id: '2', name: '李四 (已更新)', email: 'lisi@example.com', department: 'IT' },
|
|
1964
|
+
* { id: '3', name: '王五 (已更新)', email: 'wangwu@example.com', department: 'Sales' }
|
|
1965
|
+
* ];
|
|
1966
|
+
* await db.bulkUpdate('users', updatedUsers);
|
|
1967
|
+
*
|
|
1592
1968
|
* // 11. 获取所有数据
|
|
1593
1969
|
* const allUsers = await db.getAll('users');
|
|
1594
1970
|
*
|
|
1595
1971
|
* // 12. 删除数据
|
|
1596
1972
|
* await db.delete('users', '1');
|
|
1597
1973
|
*
|
|
1974
|
+
* // 12.1 批量删除数据
|
|
1975
|
+
* await db.bulkDelete('users', ['2', '3', '4']);
|
|
1976
|
+
*
|
|
1598
1977
|
* // 13. 清空存储对象
|
|
1599
1978
|
* await db.clear('users');
|
|
1600
1979
|
*
|
|
@@ -1608,7 +1987,8 @@ var IndexDBManager = /*#__PURE__*/function () {
|
|
|
1608
1987
|
* // - 使用 exists() 而不是 get() 来检查数据是否存在
|
|
1609
1988
|
* // - 为常用查询字段创建索引
|
|
1610
1989
|
* // - 使用索引查询方法来提高查询效率
|
|
1611
|
-
* // -
|
|
1990
|
+
* // - 批量操作时优先使用 bulkAdd/bulkUpdate/bulkDelete,比循环调用单条方法性能更好
|
|
1991
|
+
* // - 批量操作会自动在单个事务中完成,保证原子性
|
|
1612
1992
|
*
|
|
1613
1993
|
* // 降级方案说明:
|
|
1614
1994
|
* // - 当浏览器不支持 IndexedDB 时,会自动使用内存存储 (Map) 作为降级方案
|