remult 3.3.18 → 3.3.19-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.js +7 -6
- package/esm/remult-d1.js +1 -0
- package/esm/remult-knex/index.js +112 -2
- package/esm/remult-mongo.js +17 -8
- package/esm/remult-sqlite-core.js +1 -0
- package/esm/src/data-interfaces.js +4 -4
- package/esm/src/data-providers/array-entity-data-provider.js +14 -2
- package/esm/src/data-providers/indexed-db-data-provider.js +644 -0
- package/esm/src/data-providers/json-data-provider.js +2 -2
- package/esm/src/data-providers/rest-data-provider.js +11 -12
- package/esm/src/data-providers/sql-database.js +110 -43
- package/esm/src/remult3/RepositoryImplementation.js +90 -60
- package/index.d.ts +31 -17
- package/index.js +5 -2
- package/package.json +1 -1
- package/remult-d1.d.ts +1 -0
- package/remult-d1.js +1 -0
- package/remult-knex/index.d.ts +2 -2
- package/remult-knex/index.js +329 -44
- package/remult-mongo.js +80 -36
- package/remult-sqlite-core.d.ts +1 -0
- package/remult-sqlite-core.js +1 -0
- package/src/column-interfaces.d.ts +4 -0
- package/src/data-interfaces.d.ts +2 -3
- package/src/data-interfaces.js +4 -4
- package/src/data-providers/array-entity-data-provider.d.ts +2 -2
- package/src/data-providers/array-entity-data-provider.js +92 -14
- package/src/data-providers/indexed-db-data-provider.d.ts +37 -0
- package/src/data-providers/indexed-db-data-provider.js +1048 -0
- package/src/data-providers/json-data-provider.js +2 -2
- package/src/data-providers/rest-data-provider.d.ts +2 -3
- package/src/data-providers/rest-data-provider.js +18 -17
- package/src/data-providers/sql-database.js +254 -105
- package/src/remult3/RepositoryImplementation.d.ts +1 -1
- package/src/remult3/RepositoryImplementation.js +384 -270
- package/src/remult3/remult3.d.ts +2 -2
- package/src/sql-command.d.ts +2 -0
- package/src/standard-schema/index.d.ts +1 -1
package/remult-knex/index.js
CHANGED
|
@@ -420,24 +420,28 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
420
420
|
});
|
|
421
421
|
});
|
|
422
422
|
};
|
|
423
|
-
KnexEntityDataProvider.prototype.delete = function (
|
|
423
|
+
KnexEntityDataProvider.prototype.delete = function (ids) {
|
|
424
424
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
425
425
|
var e, f, where;
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
426
|
+
var _a;
|
|
427
|
+
return tslib_1.__generator(this, function (_b) {
|
|
428
|
+
switch (_b.label) {
|
|
429
|
+
case 0:
|
|
430
|
+
if (ids.length === 0)
|
|
431
|
+
return [2 /*return*/];
|
|
432
|
+
return [4 /*yield*/, this.init()];
|
|
429
433
|
case 1:
|
|
430
|
-
e =
|
|
434
|
+
e = _b.sent();
|
|
431
435
|
f = new FilterConsumerBridgeToKnexRequest(e, this.rawSqlWrapIdentifier);
|
|
432
|
-
filter_interfaces_js_1.Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(
|
|
436
|
+
filter_interfaces_js_1.Filter.fromEntityFilter(this.entity, (_a = this.entity.idMetadata).getIdFilter.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(ids), false))).__applyToConsumer(f);
|
|
433
437
|
return [4 /*yield*/, f.resolveWhere()];
|
|
434
438
|
case 2:
|
|
435
|
-
where =
|
|
439
|
+
where = _b.sent();
|
|
436
440
|
return [4 /*yield*/, this.getEntityFrom(e)
|
|
437
441
|
.delete()
|
|
438
442
|
.where(function (b) { return where.forEach(function (w) { return w(b); }); })];
|
|
439
443
|
case 3:
|
|
440
|
-
|
|
444
|
+
_b.sent();
|
|
441
445
|
return [2 /*return*/];
|
|
442
446
|
}
|
|
443
447
|
});
|
|
@@ -445,8 +449,227 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
445
449
|
};
|
|
446
450
|
KnexEntityDataProvider.prototype.insert = function (data, options) {
|
|
447
451
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
448
|
-
var
|
|
449
|
-
var e_5,
|
|
452
|
+
var result_1, data_1, data_1_1, row, _a, _b, e_5_1, e, batches, result, batches_1, batches_1_1, batch, _c, _d, _e, _f, e_6_1;
|
|
453
|
+
var e_5, _g, e_6, _h;
|
|
454
|
+
var _this = this;
|
|
455
|
+
return tslib_1.__generator(this, function (_j) {
|
|
456
|
+
switch (_j.label) {
|
|
457
|
+
case 0:
|
|
458
|
+
if (data.length === 0)
|
|
459
|
+
return [2 /*return*/, []];
|
|
460
|
+
if (!(isMysqlKnex(this.knex) &&
|
|
461
|
+
(0, RepositoryImplementation_js_1.isAutoIncrement)(this.entity.idMetadata.field) &&
|
|
462
|
+
(options === null || options === void 0 ? void 0 : options.select) !== 'none')) return [3 /*break*/, 9];
|
|
463
|
+
result_1 = [];
|
|
464
|
+
_j.label = 1;
|
|
465
|
+
case 1:
|
|
466
|
+
_j.trys.push([1, 6, 7, 8]);
|
|
467
|
+
data_1 = tslib_1.__values(data), data_1_1 = data_1.next();
|
|
468
|
+
_j.label = 2;
|
|
469
|
+
case 2:
|
|
470
|
+
if (!!data_1_1.done) return [3 /*break*/, 5];
|
|
471
|
+
row = data_1_1.value;
|
|
472
|
+
_b = (_a = result_1).push;
|
|
473
|
+
return [4 /*yield*/, this.insertOne(row, options)];
|
|
474
|
+
case 3:
|
|
475
|
+
_b.apply(_a, [_j.sent()]);
|
|
476
|
+
_j.label = 4;
|
|
477
|
+
case 4:
|
|
478
|
+
data_1_1 = data_1.next();
|
|
479
|
+
return [3 /*break*/, 2];
|
|
480
|
+
case 5: return [3 /*break*/, 8];
|
|
481
|
+
case 6:
|
|
482
|
+
e_5_1 = _j.sent();
|
|
483
|
+
e_5 = { error: e_5_1 };
|
|
484
|
+
return [3 /*break*/, 8];
|
|
485
|
+
case 7:
|
|
486
|
+
try {
|
|
487
|
+
if (data_1_1 && !data_1_1.done && (_g = data_1.return)) _g.call(data_1);
|
|
488
|
+
}
|
|
489
|
+
finally { if (e_5) throw e_5.error; }
|
|
490
|
+
return [7 /*endfinally*/];
|
|
491
|
+
case 8: return [2 /*return*/, result_1];
|
|
492
|
+
case 9: return [4 /*yield*/, this.init()];
|
|
493
|
+
case 10:
|
|
494
|
+
e = _j.sent();
|
|
495
|
+
batches = splitByMaxParameters(data, function (row) { return countKnexInsertBindParameters(_this.entity, e, row); }, knexMaxParametersInOneSqlStatement(this.knex));
|
|
496
|
+
result = [];
|
|
497
|
+
_j.label = 11;
|
|
498
|
+
case 11:
|
|
499
|
+
_j.trys.push([11, 16, 17, 18]);
|
|
500
|
+
batches_1 = tslib_1.__values(batches), batches_1_1 = batches_1.next();
|
|
501
|
+
_j.label = 12;
|
|
502
|
+
case 12:
|
|
503
|
+
if (!!batches_1_1.done) return [3 /*break*/, 15];
|
|
504
|
+
batch = batches_1_1.value;
|
|
505
|
+
_d = (_c = result.push).apply;
|
|
506
|
+
_e = [result];
|
|
507
|
+
_f = [[]];
|
|
508
|
+
return [4 /*yield*/, this.insertBatch(batch, e, options)];
|
|
509
|
+
case 13:
|
|
510
|
+
_d.apply(_c, _e.concat([tslib_1.__spreadArray.apply(void 0, _f.concat([tslib_1.__read.apply(void 0, [(_j.sent())]), false]))]));
|
|
511
|
+
_j.label = 14;
|
|
512
|
+
case 14:
|
|
513
|
+
batches_1_1 = batches_1.next();
|
|
514
|
+
return [3 /*break*/, 12];
|
|
515
|
+
case 15: return [3 /*break*/, 18];
|
|
516
|
+
case 16:
|
|
517
|
+
e_6_1 = _j.sent();
|
|
518
|
+
e_6 = { error: e_6_1 };
|
|
519
|
+
return [3 /*break*/, 18];
|
|
520
|
+
case 17:
|
|
521
|
+
try {
|
|
522
|
+
if (batches_1_1 && !batches_1_1.done && (_h = batches_1.return)) _h.call(batches_1);
|
|
523
|
+
}
|
|
524
|
+
finally { if (e_6) throw e_6.error; }
|
|
525
|
+
return [7 /*endfinally*/];
|
|
526
|
+
case 18: return [2 /*return*/, result];
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
};
|
|
531
|
+
KnexEntityDataProvider.prototype.insertBatch = function (batch, e, options) {
|
|
532
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
533
|
+
var cols, _loop_1, _a, _b, x, insertObjects, batch_1, batch_1_1, row, insertObject, cols_1, cols_1_1, x, v, key, e_7_1, e_8_1, insert, wantRows, result, ids;
|
|
534
|
+
var e_9, _c, e_8, _d, e_7, _e;
|
|
535
|
+
var _this = this;
|
|
536
|
+
return tslib_1.__generator(this, function (_f) {
|
|
537
|
+
switch (_f.label) {
|
|
538
|
+
case 0:
|
|
539
|
+
cols = [];
|
|
540
|
+
_loop_1 = function (x) {
|
|
541
|
+
if ((0, filter_consumer_bridge_to_sql_request_js_2.isDbReadonly)(x, e))
|
|
542
|
+
return "continue";
|
|
543
|
+
if (batch.some(function (row) {
|
|
544
|
+
return translateValueAndHandleArrayAndHandleArray(x, row[x.key]) !=
|
|
545
|
+
undefined;
|
|
546
|
+
}))
|
|
547
|
+
cols.push(x);
|
|
548
|
+
};
|
|
549
|
+
try {
|
|
550
|
+
for (_a = tslib_1.__values(this.entity.fields), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
551
|
+
x = _b.value;
|
|
552
|
+
_loop_1(x);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
556
|
+
finally {
|
|
557
|
+
try {
|
|
558
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
559
|
+
}
|
|
560
|
+
finally { if (e_9) throw e_9.error; }
|
|
561
|
+
}
|
|
562
|
+
insertObjects = [];
|
|
563
|
+
_f.label = 1;
|
|
564
|
+
case 1:
|
|
565
|
+
_f.trys.push([1, 13, 14, 15]);
|
|
566
|
+
batch_1 = tslib_1.__values(batch), batch_1_1 = batch_1.next();
|
|
567
|
+
_f.label = 2;
|
|
568
|
+
case 2:
|
|
569
|
+
if (!!batch_1_1.done) return [3 /*break*/, 12];
|
|
570
|
+
row = batch_1_1.value;
|
|
571
|
+
insertObject = {};
|
|
572
|
+
_f.label = 3;
|
|
573
|
+
case 3:
|
|
574
|
+
_f.trys.push([3, 8, 9, 10]);
|
|
575
|
+
cols_1 = (e_7 = void 0, tslib_1.__values(cols)), cols_1_1 = cols_1.next();
|
|
576
|
+
_f.label = 4;
|
|
577
|
+
case 4:
|
|
578
|
+
if (!!cols_1_1.done) return [3 /*break*/, 7];
|
|
579
|
+
x = cols_1_1.value;
|
|
580
|
+
v = translateValueAndHandleArrayAndHandleArray(x, row[x.key]);
|
|
581
|
+
return [4 /*yield*/, e.$dbNameOf(x)];
|
|
582
|
+
case 5:
|
|
583
|
+
key = _f.sent();
|
|
584
|
+
if (v != undefined)
|
|
585
|
+
insertObject[key] = v;
|
|
586
|
+
else if (x.allowNull)
|
|
587
|
+
insertObject[key] = null;
|
|
588
|
+
else
|
|
589
|
+
insertObject[key] = this.knex.raw('DEFAULT');
|
|
590
|
+
_f.label = 6;
|
|
591
|
+
case 6:
|
|
592
|
+
cols_1_1 = cols_1.next();
|
|
593
|
+
return [3 /*break*/, 4];
|
|
594
|
+
case 7: return [3 /*break*/, 10];
|
|
595
|
+
case 8:
|
|
596
|
+
e_7_1 = _f.sent();
|
|
597
|
+
e_7 = { error: e_7_1 };
|
|
598
|
+
return [3 /*break*/, 10];
|
|
599
|
+
case 9:
|
|
600
|
+
try {
|
|
601
|
+
if (cols_1_1 && !cols_1_1.done && (_e = cols_1.return)) _e.call(cols_1);
|
|
602
|
+
}
|
|
603
|
+
finally { if (e_7) throw e_7.error; }
|
|
604
|
+
return [7 /*endfinally*/];
|
|
605
|
+
case 10:
|
|
606
|
+
insertObjects.push(insertObject);
|
|
607
|
+
_f.label = 11;
|
|
608
|
+
case 11:
|
|
609
|
+
batch_1_1 = batch_1.next();
|
|
610
|
+
return [3 /*break*/, 2];
|
|
611
|
+
case 12: return [3 /*break*/, 15];
|
|
612
|
+
case 13:
|
|
613
|
+
e_8_1 = _f.sent();
|
|
614
|
+
e_8 = { error: e_8_1 };
|
|
615
|
+
return [3 /*break*/, 15];
|
|
616
|
+
case 14:
|
|
617
|
+
try {
|
|
618
|
+
if (batch_1_1 && !batch_1_1.done && (_d = batch_1.return)) _d.call(batch_1);
|
|
619
|
+
}
|
|
620
|
+
finally { if (e_8) throw e_8.error; }
|
|
621
|
+
return [7 /*endfinally*/];
|
|
622
|
+
case 15:
|
|
623
|
+
insert = this.getEntityFrom(e).insert(insertObjects);
|
|
624
|
+
wantRows = (options === null || options === void 0 ? void 0 : options.select) !== 'none';
|
|
625
|
+
if (!((0, RepositoryImplementation_js_1.isAutoIncrement)(this.entity.idMetadata.field) && wantRows)) return [3 /*break*/, 17];
|
|
626
|
+
return [4 /*yield*/, insert.returning(this.entity.idMetadata.field.dbName)];
|
|
627
|
+
case 16:
|
|
628
|
+
result = _f.sent();
|
|
629
|
+
ids = result.map(function (r) {
|
|
630
|
+
return r && typeof r === 'object'
|
|
631
|
+
? r[_this.entity.idMetadata.field.dbName]
|
|
632
|
+
: r;
|
|
633
|
+
});
|
|
634
|
+
return [2 /*return*/, this.loadRowsByIds(ids)];
|
|
635
|
+
case 17: return [4 /*yield*/, insert];
|
|
636
|
+
case 18:
|
|
637
|
+
_f.sent();
|
|
638
|
+
if (!wantRows)
|
|
639
|
+
return [2 /*return*/, batch.map(function () { return undefined; })];
|
|
640
|
+
return [2 /*return*/, this.loadRowsByIds(batch.map(function (row) { return _this.entity.idMetadata.getId(row); }))];
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
});
|
|
644
|
+
};
|
|
645
|
+
KnexEntityDataProvider.prototype.loadRowsByIds = function (ids) {
|
|
646
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
647
|
+
var found, byId;
|
|
648
|
+
var _a;
|
|
649
|
+
var _this = this;
|
|
650
|
+
return tslib_1.__generator(this, function (_b) {
|
|
651
|
+
switch (_b.label) {
|
|
652
|
+
case 0: return [4 /*yield*/, this.find({
|
|
653
|
+
where: filter_interfaces_js_1.Filter.fromEntityFilter(this.entity, (_a = this.entity.idMetadata).getIdFilter.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(ids), false))),
|
|
654
|
+
})];
|
|
655
|
+
case 1:
|
|
656
|
+
found = _b.sent();
|
|
657
|
+
byId = new Map(found.map(function (row) { return [_this.entity.idMetadata.getId(row) + '', row]; }));
|
|
658
|
+
return [2 /*return*/, ids.map(function (id) {
|
|
659
|
+
var row = byId.get(id + '');
|
|
660
|
+
if (!row)
|
|
661
|
+
throw new Error("Failed to insert row - result contained ".concat(found.length, " rows"));
|
|
662
|
+
return row;
|
|
663
|
+
})];
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
});
|
|
667
|
+
};
|
|
668
|
+
//@internal
|
|
669
|
+
KnexEntityDataProvider.prototype.insertOne = function (data, options) {
|
|
670
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
671
|
+
var e, insertObject, _a, _b, x, v, key, e_10_1, insert, newId_1, result, result;
|
|
672
|
+
var e_10, _c;
|
|
450
673
|
var _this = this;
|
|
451
674
|
return tslib_1.__generator(this, function (_d) {
|
|
452
675
|
switch (_d.label) {
|
|
@@ -477,14 +700,14 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
477
700
|
return [3 /*break*/, 3];
|
|
478
701
|
case 7: return [3 /*break*/, 10];
|
|
479
702
|
case 8:
|
|
480
|
-
|
|
481
|
-
|
|
703
|
+
e_10_1 = _d.sent();
|
|
704
|
+
e_10 = { error: e_10_1 };
|
|
482
705
|
return [3 /*break*/, 10];
|
|
483
706
|
case 9:
|
|
484
707
|
try {
|
|
485
708
|
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
486
709
|
}
|
|
487
|
-
finally { if (
|
|
710
|
+
finally { if (e_10) throw e_10.error; }
|
|
488
711
|
return [7 /*endfinally*/];
|
|
489
712
|
case 10:
|
|
490
713
|
insert = this.getEntityFrom(e).insert(insertObject);
|
|
@@ -534,8 +757,8 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
534
757
|
}
|
|
535
758
|
FilterConsumerBridgeToKnexRequest.prototype.resolveWhere = function () {
|
|
536
759
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
537
|
-
var p, p_1, p_1_1, pr,
|
|
538
|
-
var
|
|
760
|
+
var p, p_1, p_1_1, pr, e_11_1;
|
|
761
|
+
var e_11, _a;
|
|
539
762
|
return tslib_1.__generator(this, function (_b) {
|
|
540
763
|
switch (_b.label) {
|
|
541
764
|
case 0:
|
|
@@ -545,7 +768,7 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
545
768
|
_b.label = 1;
|
|
546
769
|
case 1:
|
|
547
770
|
_b.trys.push([1, 6, 7, 8]);
|
|
548
|
-
p_1 = (
|
|
771
|
+
p_1 = (e_11 = void 0, tslib_1.__values(p)), p_1_1 = p_1.next();
|
|
549
772
|
_b.label = 2;
|
|
550
773
|
case 2:
|
|
551
774
|
if (!!p_1_1.done) return [3 /*break*/, 5];
|
|
@@ -559,14 +782,14 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
559
782
|
return [3 /*break*/, 2];
|
|
560
783
|
case 5: return [3 /*break*/, 8];
|
|
561
784
|
case 6:
|
|
562
|
-
|
|
563
|
-
|
|
785
|
+
e_11_1 = _b.sent();
|
|
786
|
+
e_11 = { error: e_11_1 };
|
|
564
787
|
return [3 /*break*/, 8];
|
|
565
788
|
case 7:
|
|
566
789
|
try {
|
|
567
790
|
if (p_1_1 && !p_1_1.done && (_a = p_1.return)) _a.call(p_1);
|
|
568
791
|
}
|
|
569
|
-
finally { if (
|
|
792
|
+
finally { if (e_11) throw e_11.error; }
|
|
570
793
|
return [7 /*endfinally*/];
|
|
571
794
|
case 8: return [3 /*break*/, 0];
|
|
572
795
|
case 9: return [2 /*return*/, this.result];
|
|
@@ -580,13 +803,13 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
580
803
|
FilterConsumerBridgeToKnexRequest.prototype.or = function (orElements) {
|
|
581
804
|
var _this = this;
|
|
582
805
|
this.promises.push((function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
583
|
-
var result,
|
|
584
|
-
var
|
|
806
|
+
var result, _loop_2, this_1, orElements_1, orElements_1_1, element, state_1, e_12_1;
|
|
807
|
+
var e_12, _a;
|
|
585
808
|
return tslib_1.__generator(this, function (_b) {
|
|
586
809
|
switch (_b.label) {
|
|
587
810
|
case 0:
|
|
588
811
|
result = [];
|
|
589
|
-
|
|
812
|
+
_loop_2 = function (element) {
|
|
590
813
|
var f, where;
|
|
591
814
|
return tslib_1.__generator(this, function (_c) {
|
|
592
815
|
switch (_c.label) {
|
|
@@ -619,7 +842,7 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
619
842
|
case 2:
|
|
620
843
|
if (!!orElements_1_1.done) return [3 /*break*/, 5];
|
|
621
844
|
element = orElements_1_1.value;
|
|
622
|
-
return [5 /*yield**/,
|
|
845
|
+
return [5 /*yield**/, _loop_2(element)];
|
|
623
846
|
case 3:
|
|
624
847
|
state_1 = _b.sent();
|
|
625
848
|
if (typeof state_1 === "object")
|
|
@@ -630,14 +853,14 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
630
853
|
return [3 /*break*/, 2];
|
|
631
854
|
case 5: return [3 /*break*/, 8];
|
|
632
855
|
case 6:
|
|
633
|
-
|
|
634
|
-
|
|
856
|
+
e_12_1 = _b.sent();
|
|
857
|
+
e_12 = { error: e_12_1 };
|
|
635
858
|
return [3 /*break*/, 8];
|
|
636
859
|
case 7:
|
|
637
860
|
try {
|
|
638
861
|
if (orElements_1_1 && !orElements_1_1.done && (_a = orElements_1.return)) _a.call(orElements_1);
|
|
639
862
|
}
|
|
640
|
-
finally { if (
|
|
863
|
+
finally { if (e_12) throw e_12.error; }
|
|
641
864
|
return [7 /*endfinally*/];
|
|
642
865
|
case 8:
|
|
643
866
|
if (result.length > 0) {
|
|
@@ -807,8 +1030,8 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
807
1030
|
}
|
|
808
1031
|
KnexSchemaBuilder.prototype.ensureSchema = function (entities) {
|
|
809
1032
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
810
|
-
var entities_1, entities_1_1, entity, e, err_2,
|
|
811
|
-
var
|
|
1033
|
+
var entities_1, entities_1_1, entity, e, err_2, e_13_1;
|
|
1034
|
+
var e_13, _a;
|
|
812
1035
|
return tslib_1.__generator(this, function (_b) {
|
|
813
1036
|
switch (_b.label) {
|
|
814
1037
|
case 0:
|
|
@@ -842,14 +1065,14 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
842
1065
|
return [3 /*break*/, 1];
|
|
843
1066
|
case 9: return [3 /*break*/, 12];
|
|
844
1067
|
case 10:
|
|
845
|
-
|
|
846
|
-
|
|
1068
|
+
e_13_1 = _b.sent();
|
|
1069
|
+
e_13 = { error: e_13_1 };
|
|
847
1070
|
return [3 /*break*/, 12];
|
|
848
1071
|
case 11:
|
|
849
1072
|
try {
|
|
850
1073
|
if (entities_1_1 && !entities_1_1.done && (_a = entities_1.return)) _a.call(entities_1);
|
|
851
1074
|
}
|
|
852
|
-
finally { if (
|
|
1075
|
+
finally { if (e_13) throw e_13.error; }
|
|
853
1076
|
return [7 /*endfinally*/];
|
|
854
1077
|
case 12: return [2 /*return*/];
|
|
855
1078
|
}
|
|
@@ -877,7 +1100,7 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
877
1100
|
});
|
|
878
1101
|
};
|
|
879
1102
|
KnexSchemaBuilder.prototype.createTableKnexCommand = function (entity, e) {
|
|
880
|
-
var
|
|
1103
|
+
var e_14, _a;
|
|
881
1104
|
var _this = this;
|
|
882
1105
|
var cols = new Map();
|
|
883
1106
|
try {
|
|
@@ -889,15 +1112,15 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
889
1112
|
});
|
|
890
1113
|
}
|
|
891
1114
|
}
|
|
892
|
-
catch (
|
|
1115
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
893
1116
|
finally {
|
|
894
1117
|
try {
|
|
895
1118
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
896
1119
|
}
|
|
897
|
-
finally { if (
|
|
1120
|
+
finally { if (e_14) throw e_14.error; }
|
|
898
1121
|
}
|
|
899
1122
|
return this.knex.schema.createTable(e.$entityName, function (b) {
|
|
900
|
-
var
|
|
1123
|
+
var e_15, _a;
|
|
901
1124
|
try {
|
|
902
1125
|
for (var _b = tslib_1.__values(entity.fields), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
903
1126
|
var x = _c.value;
|
|
@@ -910,12 +1133,12 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
910
1133
|
}
|
|
911
1134
|
}
|
|
912
1135
|
}
|
|
913
|
-
catch (
|
|
1136
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
914
1137
|
finally {
|
|
915
1138
|
try {
|
|
916
1139
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
917
1140
|
}
|
|
918
|
-
finally { if (
|
|
1141
|
+
finally { if (e_15) throw e_15.error; }
|
|
919
1142
|
}
|
|
920
1143
|
b.primary(entity.idMetadata.fields.map(function (f) { return e.$dbNameOf(f); }));
|
|
921
1144
|
});
|
|
@@ -952,8 +1175,8 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
952
1175
|
};
|
|
953
1176
|
KnexSchemaBuilder.prototype.verifyAllColumns = function (entity) {
|
|
954
1177
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
955
|
-
var e,
|
|
956
|
-
var
|
|
1178
|
+
var e, _loop_3, this_2, _a, _b, col, e_16_1, err_3;
|
|
1179
|
+
var e_16, _c;
|
|
957
1180
|
return tslib_1.__generator(this, function (_d) {
|
|
958
1181
|
switch (_d.label) {
|
|
959
1182
|
case 0: return [4 /*yield*/, (0, filter_consumer_bridge_to_sql_request_js_2.dbNamesOf)(entity, function (x) { return x; })];
|
|
@@ -962,7 +1185,7 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
962
1185
|
_d.label = 2;
|
|
963
1186
|
case 2:
|
|
964
1187
|
_d.trys.push([2, 11, , 12]);
|
|
965
|
-
|
|
1188
|
+
_loop_3 = function (col) {
|
|
966
1189
|
return tslib_1.__generator(this, function (_e) {
|
|
967
1190
|
switch (_e.label) {
|
|
968
1191
|
case 0:
|
|
@@ -984,7 +1207,7 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
984
1207
|
case 4:
|
|
985
1208
|
if (!!_b.done) return [3 /*break*/, 7];
|
|
986
1209
|
col = _b.value;
|
|
987
|
-
return [5 /*yield**/,
|
|
1210
|
+
return [5 /*yield**/, _loop_3(col)];
|
|
988
1211
|
case 5:
|
|
989
1212
|
_d.sent();
|
|
990
1213
|
_d.label = 6;
|
|
@@ -993,14 +1216,14 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
993
1216
|
return [3 /*break*/, 4];
|
|
994
1217
|
case 7: return [3 /*break*/, 10];
|
|
995
1218
|
case 8:
|
|
996
|
-
|
|
997
|
-
|
|
1219
|
+
e_16_1 = _d.sent();
|
|
1220
|
+
e_16 = { error: e_16_1 };
|
|
998
1221
|
return [3 /*break*/, 10];
|
|
999
1222
|
case 9:
|
|
1000
1223
|
try {
|
|
1001
1224
|
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1002
1225
|
}
|
|
1003
|
-
finally { if (
|
|
1226
|
+
finally { if (e_16) throw e_16.error; }
|
|
1004
1227
|
return [7 /*endfinally*/];
|
|
1005
1228
|
case 10: return [3 /*break*/, 12];
|
|
1006
1229
|
case 11:
|
|
@@ -1113,6 +1336,68 @@ function createKnexDataProvider(config) {
|
|
|
1113
1336
|
});
|
|
1114
1337
|
});
|
|
1115
1338
|
}
|
|
1339
|
+
var defaultMaxParametersInOneSqlStatement = 2000;
|
|
1340
|
+
function isMysqlKnex(knex) {
|
|
1341
|
+
var client = knex.client.config.client;
|
|
1342
|
+
return client === 'mysql2' || client === 'mysql';
|
|
1343
|
+
}
|
|
1344
|
+
function knexMaxParametersInOneSqlStatement(knex) {
|
|
1345
|
+
var _a;
|
|
1346
|
+
var client = String((_a = knex.client.config.client) !== null && _a !== void 0 ? _a : '');
|
|
1347
|
+
if (client.includes('sqlite'))
|
|
1348
|
+
return 999;
|
|
1349
|
+
return defaultMaxParametersInOneSqlStatement;
|
|
1350
|
+
}
|
|
1351
|
+
function splitByMaxParameters(items, parametersInItem, maxParameters) {
|
|
1352
|
+
var e_17, _a;
|
|
1353
|
+
var batches = [];
|
|
1354
|
+
var batch = [];
|
|
1355
|
+
var params = 0;
|
|
1356
|
+
try {
|
|
1357
|
+
for (var items_1 = tslib_1.__values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
1358
|
+
var item = items_1_1.value;
|
|
1359
|
+
var n = parametersInItem(item);
|
|
1360
|
+
if (batch.length > 0 && params + n > maxParameters) {
|
|
1361
|
+
batches.push(batch);
|
|
1362
|
+
batch = [];
|
|
1363
|
+
params = 0;
|
|
1364
|
+
}
|
|
1365
|
+
batch.push(item);
|
|
1366
|
+
params += n;
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
1370
|
+
finally {
|
|
1371
|
+
try {
|
|
1372
|
+
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
|
1373
|
+
}
|
|
1374
|
+
finally { if (e_17) throw e_17.error; }
|
|
1375
|
+
}
|
|
1376
|
+
if (batch.length)
|
|
1377
|
+
batches.push(batch);
|
|
1378
|
+
return batches;
|
|
1379
|
+
}
|
|
1380
|
+
function countKnexInsertBindParameters(entity, e, row) {
|
|
1381
|
+
var e_18, _a;
|
|
1382
|
+
var n = 0;
|
|
1383
|
+
try {
|
|
1384
|
+
for (var _b = tslib_1.__values(entity.fields), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1385
|
+
var x = _c.value;
|
|
1386
|
+
if ((0, filter_consumer_bridge_to_sql_request_js_2.isDbReadonly)(x, e))
|
|
1387
|
+
continue;
|
|
1388
|
+
if (translateValueAndHandleArrayAndHandleArray(x, row[x.key]) != undefined)
|
|
1389
|
+
n++;
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
1393
|
+
finally {
|
|
1394
|
+
try {
|
|
1395
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1396
|
+
}
|
|
1397
|
+
finally { if (e_18) throw e_18.error; }
|
|
1398
|
+
}
|
|
1399
|
+
return n;
|
|
1400
|
+
}
|
|
1116
1401
|
function translateValueAndHandleArrayAndHandleArray(field, val) {
|
|
1117
1402
|
var result = field.valueConverter.toDb(val);
|
|
1118
1403
|
if (Array.isArray(result))
|