remult 3.3.19-next.2 → 3.4.0-next.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.
- package/SseSubscriptionServer.d.ts +2 -0
- package/SseSubscriptionServer.js +4 -2
- package/esm/SseSubscriptionServer.js +3 -1
- package/esm/index.js +6 -7
- package/esm/live-query/data-provider-live-query-storage.js +3 -1
- package/esm/remult-d1.js +0 -1
- package/esm/remult-knex/index.js +2 -112
- package/esm/remult-mongo.js +8 -17
- package/esm/remult-sqlite-core.js +0 -1
- package/esm/server/remult-api-server.js +6 -1
- package/esm/src/data-api.js +1 -0
- package/esm/src/data-interfaces.js +4 -4
- package/esm/src/data-providers/array-entity-data-provider.js +2 -14
- package/esm/src/data-providers/json-data-provider.js +2 -2
- package/esm/src/data-providers/rest-data-provider.js +12 -11
- package/esm/src/data-providers/sql-database.js +43 -110
- package/esm/src/live-query/LiveQueryClient.js +163 -52
- package/esm/src/live-query/SseSubscriptionClient.js +101 -43
- package/esm/src/live-query/SubscriptionChannel.js +37 -3
- package/esm/src/live-query/SubscriptionServer.js +11 -3
- package/esm/src/remult3/RepositoryImplementation.js +60 -90
- package/esm/src/remult3/remult3.js +6 -0
- package/index.d.ts +17 -31
- package/index.js +2 -5
- package/live-query/data-provider-live-query-storage.d.ts +4 -1
- package/live-query/data-provider-live-query-storage.js +18 -15
- package/package.json +1 -1
- package/remult-d1.d.ts +0 -1
- package/remult-d1.js +0 -1
- package/remult-knex/index.js +44 -329
- package/remult-mongo.js +36 -80
- package/remult-sqlite-core.d.ts +0 -1
- package/remult-sqlite-core.js +0 -1
- package/server/remult-api-server.js +13 -9
- package/src/data-api.js +1 -0
- package/src/data-interfaces.d.ts +3 -2
- 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 +14 -92
- package/src/data-providers/json-data-provider.js +2 -2
- package/src/data-providers/rest-data-provider.d.ts +3 -2
- package/src/data-providers/rest-data-provider.js +17 -18
- package/src/data-providers/sql-database.js +105 -254
- package/src/live-query/LiveQueryClient.js +215 -97
- package/src/live-query/SseSubscriptionClient.js +143 -83
- package/src/live-query/SubscriptionChannel.d.ts +8 -0
- package/src/live-query/SubscriptionChannel.js +47 -9
- package/src/live-query/SubscriptionServer.d.ts +7 -2
- package/src/live-query/SubscriptionServer.js +20 -10
- package/src/remult3/RepositoryImplementation.d.ts +1 -1
- package/src/remult3/RepositoryImplementation.js +270 -384
- package/src/remult3/remult3.d.ts +8 -2
- package/src/remult3/remult3.js +6 -0
- package/src/sql-command.d.ts +0 -2
- package/src/standard-schema/index.d.ts +1 -1
- package/esm/src/data-providers/indexed-db-data-provider.js +0 -811
- package/src/data-providers/indexed-db-data-provider.d.ts +0 -39
- package/src/data-providers/indexed-db-data-provider.js +0 -1387
|
@@ -185,8 +185,6 @@ var SqlDatabase = /** @class */ (function () {
|
|
|
185
185
|
doesNotSupportReturningSyntax: this.sql.doesNotSupportReturningSyntax,
|
|
186
186
|
doesNotSupportReturningSyntaxOnlyForUpdate: this.sql.doesNotSupportReturningSyntaxOnlyForUpdate,
|
|
187
187
|
orderByNullsFirst: this.sql.orderByNullsFirst,
|
|
188
|
-
afterMutation: this.sql.afterMutation,
|
|
189
|
-
maxParametersInOneSqlStatement: this.sql.maxParametersInOneSqlStatement,
|
|
190
188
|
}))];
|
|
191
189
|
case 2:
|
|
192
190
|
_a.sent();
|
|
@@ -272,57 +270,6 @@ var SqlDatabase = /** @class */ (function () {
|
|
|
272
270
|
return SqlDatabase;
|
|
273
271
|
}());
|
|
274
272
|
exports.SqlDatabase = SqlDatabase;
|
|
275
|
-
var defaultMaxParametersInOneSqlStatement = 2000;
|
|
276
|
-
function splitByMaxParameters(items, parametersInItem, maxParameters) {
|
|
277
|
-
var e_2, _a;
|
|
278
|
-
var batches = [];
|
|
279
|
-
var batch = [];
|
|
280
|
-
var params = 0;
|
|
281
|
-
try {
|
|
282
|
-
for (var items_1 = tslib_1.__values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
283
|
-
var item = items_1_1.value;
|
|
284
|
-
var n = parametersInItem(item);
|
|
285
|
-
if (batch.length > 0 && params + n > maxParameters) {
|
|
286
|
-
batches.push(batch);
|
|
287
|
-
batch = [];
|
|
288
|
-
params = 0;
|
|
289
|
-
}
|
|
290
|
-
batch.push(item);
|
|
291
|
-
params += n;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
295
|
-
finally {
|
|
296
|
-
try {
|
|
297
|
-
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
|
298
|
-
}
|
|
299
|
-
finally { if (e_2) throw e_2.error; }
|
|
300
|
-
}
|
|
301
|
-
if (batch.length)
|
|
302
|
-
batches.push(batch);
|
|
303
|
-
return batches;
|
|
304
|
-
}
|
|
305
|
-
function countInsertBindParameters(entity, e, row) {
|
|
306
|
-
var e_3, _a;
|
|
307
|
-
var n = 0;
|
|
308
|
-
try {
|
|
309
|
-
for (var _b = tslib_1.__values(entity.fields), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
310
|
-
var x = _c.value;
|
|
311
|
-
if ((0, filter_consumer_bridge_to_sql_request_js_1.isDbReadonly)(x, e))
|
|
312
|
-
continue;
|
|
313
|
-
if (x.valueConverter.toDb(row[x.key]) != undefined)
|
|
314
|
-
n++;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
318
|
-
finally {
|
|
319
|
-
try {
|
|
320
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
321
|
-
}
|
|
322
|
-
finally { if (e_3) throw e_3.error; }
|
|
323
|
-
}
|
|
324
|
-
return n;
|
|
325
|
-
}
|
|
326
273
|
var icons = new Map([
|
|
327
274
|
// CRUD
|
|
328
275
|
['INSERT', '⚪'], // Used to insert new data into a database.
|
|
@@ -467,8 +414,8 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
|
|
|
467
414
|
};
|
|
468
415
|
ActualSQLEntityDataProvider.prototype.find = function (options) {
|
|
469
416
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
470
|
-
var e, r, _a, colKeys, select, where, _b, first, segs, _c, _d, s, segs_1, segs_1_1, c, _e, _f,
|
|
471
|
-
var
|
|
417
|
+
var e, r, _a, colKeys, select, where, _b, first, segs, _c, _d, s, segs_1, segs_1_1, c, _e, _f, e_2_1, page;
|
|
418
|
+
var e_3, _g, e_2, _h;
|
|
472
419
|
var _this = this;
|
|
473
420
|
return tslib_1.__generator(this, function (_j) {
|
|
474
421
|
switch (_j.label) {
|
|
@@ -506,12 +453,12 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
|
|
|
506
453
|
segs.push(s);
|
|
507
454
|
}
|
|
508
455
|
}
|
|
509
|
-
catch (
|
|
456
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
510
457
|
finally {
|
|
511
458
|
try {
|
|
512
459
|
if (_d && !_d.done && (_g = _c.return)) _g.call(_c);
|
|
513
460
|
}
|
|
514
|
-
finally { if (
|
|
461
|
+
finally { if (e_3) throw e_3.error; }
|
|
515
462
|
}
|
|
516
463
|
_j.label = 5;
|
|
517
464
|
case 5:
|
|
@@ -551,14 +498,14 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
|
|
|
551
498
|
return [3 /*break*/, 6];
|
|
552
499
|
case 11: return [3 /*break*/, 14];
|
|
553
500
|
case 12:
|
|
554
|
-
|
|
555
|
-
|
|
501
|
+
e_2_1 = _j.sent();
|
|
502
|
+
e_2 = { error: e_2_1 };
|
|
556
503
|
return [3 /*break*/, 14];
|
|
557
504
|
case 13:
|
|
558
505
|
try {
|
|
559
506
|
if (segs_1_1 && !segs_1_1.done && (_h = segs_1.return)) _h.call(segs_1);
|
|
560
507
|
}
|
|
561
|
-
finally { if (
|
|
508
|
+
finally { if (e_2) throw e_2.error; }
|
|
562
509
|
return [7 /*endfinally*/];
|
|
563
510
|
case 14:
|
|
564
511
|
if (options.limit) {
|
|
@@ -596,8 +543,8 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
|
|
|
596
543
|
};
|
|
597
544
|
ActualSQLEntityDataProvider.prototype.buildSelect = function (e, r, selectedFields, args) {
|
|
598
545
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
599
|
-
var select, colKeys, _a, _b, x, sql,
|
|
600
|
-
var
|
|
546
|
+
var select, colKeys, _a, _b, x, sql, e_4_1;
|
|
547
|
+
var e_4, _c;
|
|
601
548
|
return tslib_1.__generator(this, function (_d) {
|
|
602
549
|
switch (_d.label) {
|
|
603
550
|
case 0:
|
|
@@ -640,14 +587,14 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
|
|
|
640
587
|
return [3 /*break*/, 2];
|
|
641
588
|
case 8: return [3 /*break*/, 11];
|
|
642
589
|
case 9:
|
|
643
|
-
|
|
644
|
-
|
|
590
|
+
e_4_1 = _d.sent();
|
|
591
|
+
e_4 = { error: e_4_1 };
|
|
645
592
|
return [3 /*break*/, 11];
|
|
646
593
|
case 10:
|
|
647
594
|
try {
|
|
648
595
|
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
649
596
|
}
|
|
650
|
-
finally { if (
|
|
597
|
+
finally { if (e_4) throw e_4.error; }
|
|
651
598
|
return [7 /*endfinally*/];
|
|
652
599
|
case 11: return [2 /*return*/, { colKeys: colKeys, select: select }];
|
|
653
600
|
}
|
|
@@ -657,7 +604,7 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
|
|
|
657
604
|
ActualSQLEntityDataProvider.prototype.update = function (id, data, options) {
|
|
658
605
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
659
606
|
var e, r, statement, added, _a, _b, x, v, idFilter, f, _c, _d, colKeys, select, returning;
|
|
660
|
-
var
|
|
607
|
+
var e_5, _e;
|
|
661
608
|
var _this = this;
|
|
662
609
|
return tslib_1.__generator(this, function (_f) {
|
|
663
610
|
switch (_f.label) {
|
|
@@ -684,12 +631,12 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
|
|
|
684
631
|
}
|
|
685
632
|
}
|
|
686
633
|
}
|
|
687
|
-
catch (
|
|
634
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
688
635
|
finally {
|
|
689
636
|
try {
|
|
690
637
|
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
691
638
|
}
|
|
692
|
-
finally { if (
|
|
639
|
+
finally { if (e_5) throw e_5.error; }
|
|
693
640
|
}
|
|
694
641
|
idFilter = this.entity.idMetadata.getIdFilter(id);
|
|
695
642
|
f = new filter_consumer_bridge_to_sql_request_js_1.FilterConsumerBridgeToSqlRequest(r, e);
|
|
@@ -730,27 +677,23 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
|
|
|
730
677
|
});
|
|
731
678
|
});
|
|
732
679
|
};
|
|
733
|
-
ActualSQLEntityDataProvider.prototype.delete = function (
|
|
680
|
+
ActualSQLEntityDataProvider.prototype.delete = function (id) {
|
|
734
681
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
735
682
|
var e, r, f, statement, _a;
|
|
736
|
-
var _b;
|
|
737
683
|
var _this = this;
|
|
738
|
-
return tslib_1.__generator(this, function (
|
|
739
|
-
switch (
|
|
740
|
-
case 0:
|
|
741
|
-
if (ids.length === 0)
|
|
742
|
-
return [2 /*return*/];
|
|
743
|
-
return [4 /*yield*/, this.init()];
|
|
684
|
+
return tslib_1.__generator(this, function (_b) {
|
|
685
|
+
switch (_b.label) {
|
|
686
|
+
case 0: return [4 /*yield*/, this.init()];
|
|
744
687
|
case 1:
|
|
745
|
-
e =
|
|
688
|
+
e = _b.sent();
|
|
746
689
|
r = this.sql.createCommand();
|
|
747
690
|
f = new filter_consumer_bridge_to_sql_request_js_1.FilterConsumerBridgeToSqlRequest(r, e);
|
|
748
|
-
filter_interfaces_js_1.Filter.fromEntityFilter(this.entity,
|
|
691
|
+
filter_interfaces_js_1.Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
749
692
|
statement = 'delete from ' + e.$entityName;
|
|
750
693
|
_a = statement;
|
|
751
694
|
return [4 /*yield*/, f.resolveWhere()];
|
|
752
695
|
case 2:
|
|
753
|
-
statement = _a +
|
|
696
|
+
statement = _a + _b.sent();
|
|
754
697
|
return [2 /*return*/, r.execute(statement).then(function () {
|
|
755
698
|
var _a, _b;
|
|
756
699
|
(_b = (_a = _this.sql._getSourceSql()).afterMutation) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
@@ -761,172 +704,80 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
|
|
|
761
704
|
};
|
|
762
705
|
ActualSQLEntityDataProvider.prototype.insert = function (data, options) {
|
|
763
706
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
764
|
-
var e,
|
|
765
|
-
var
|
|
707
|
+
var e, r, cols, vals, added, _a, _b, x, v, statement, _c, colKeys, select;
|
|
708
|
+
var e_6, _d;
|
|
766
709
|
var _this = this;
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
case 0:
|
|
771
|
-
if (data.length === 0)
|
|
772
|
-
return [2 /*return*/, []];
|
|
773
|
-
return [4 /*yield*/, this.init()];
|
|
710
|
+
return tslib_1.__generator(this, function (_e) {
|
|
711
|
+
switch (_e.label) {
|
|
712
|
+
case 0: return [4 /*yield*/, this.init()];
|
|
774
713
|
case 1:
|
|
775
|
-
e =
|
|
776
|
-
maxParams = (_f = this.strategy.maxParametersInOneSqlStatement) !== null && _f !== void 0 ? _f : defaultMaxParametersInOneSqlStatement;
|
|
777
|
-
batches = splitByMaxParameters(data, function (row) { return countInsertBindParameters(_this.entity, e, row); }, maxParams);
|
|
778
|
-
result = [];
|
|
779
|
-
_g.label = 2;
|
|
780
|
-
case 2:
|
|
781
|
-
_g.trys.push([2, 7, 8, 9]);
|
|
782
|
-
batches_1 = tslib_1.__values(batches), batches_1_1 = batches_1.next();
|
|
783
|
-
_g.label = 3;
|
|
784
|
-
case 3:
|
|
785
|
-
if (!!batches_1_1.done) return [3 /*break*/, 6];
|
|
786
|
-
batch = batches_1_1.value;
|
|
787
|
-
_b = (_a = result.push).apply;
|
|
788
|
-
_c = [result];
|
|
789
|
-
_d = [[]];
|
|
790
|
-
return [4 /*yield*/, this.insertBatch(batch, e, options)];
|
|
791
|
-
case 4:
|
|
792
|
-
_b.apply(_a, _c.concat([tslib_1.__spreadArray.apply(void 0, _d.concat([tslib_1.__read.apply(void 0, [(_g.sent())]), false]))]));
|
|
793
|
-
_g.label = 5;
|
|
794
|
-
case 5:
|
|
795
|
-
batches_1_1 = batches_1.next();
|
|
796
|
-
return [3 /*break*/, 3];
|
|
797
|
-
case 6: return [3 /*break*/, 9];
|
|
798
|
-
case 7:
|
|
799
|
-
e_8_1 = _g.sent();
|
|
800
|
-
e_8 = { error: e_8_1 };
|
|
801
|
-
return [3 /*break*/, 9];
|
|
802
|
-
case 8:
|
|
803
|
-
try {
|
|
804
|
-
if (batches_1_1 && !batches_1_1.done && (_e = batches_1.return)) _e.call(batches_1);
|
|
805
|
-
}
|
|
806
|
-
finally { if (e_8) throw e_8.error; }
|
|
807
|
-
return [7 /*endfinally*/];
|
|
808
|
-
case 9: return [2 /*return*/, result];
|
|
809
|
-
}
|
|
810
|
-
});
|
|
811
|
-
});
|
|
812
|
-
};
|
|
813
|
-
//@internal
|
|
814
|
-
ActualSQLEntityDataProvider.prototype.insertOne = function (data, options) {
|
|
815
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
816
|
-
return tslib_1.__generator(this, function (_a) {
|
|
817
|
-
switch (_a.label) {
|
|
818
|
-
case 0: return [4 /*yield*/, this.insert([data], options)];
|
|
819
|
-
case 1: return [2 /*return*/, (_a.sent())[0]];
|
|
820
|
-
}
|
|
821
|
-
});
|
|
822
|
-
});
|
|
823
|
-
};
|
|
824
|
-
ActualSQLEntityDataProvider.prototype.insertBatch = function (batch, e, options) {
|
|
825
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
826
|
-
var r, cols, _loop_1, _a, _b, x, colSql, vals, i, i, j, x, v, statement, _c, colKeys, select, source, wantRows, sql, lastId, ids, id;
|
|
827
|
-
var e_9, _d;
|
|
828
|
-
var _this = this;
|
|
829
|
-
var _e;
|
|
830
|
-
return tslib_1.__generator(this, function (_f) {
|
|
831
|
-
switch (_f.label) {
|
|
832
|
-
case 0:
|
|
714
|
+
e = _e.sent();
|
|
833
715
|
r = this.sql.createCommand();
|
|
834
|
-
cols =
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
return "continue";
|
|
838
|
-
if (batch.some(function (row) { return x.valueConverter.toDb(row[x.key]) != undefined; }))
|
|
839
|
-
cols.push(x);
|
|
840
|
-
};
|
|
716
|
+
cols = '';
|
|
717
|
+
vals = '';
|
|
718
|
+
added = false;
|
|
841
719
|
try {
|
|
842
720
|
for (_a = tslib_1.__values(this.entity.fields), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
843
721
|
x = _b.value;
|
|
844
|
-
|
|
722
|
+
if ((0, filter_consumer_bridge_to_sql_request_js_1.isDbReadonly)(x, e)) {
|
|
723
|
+
}
|
|
724
|
+
else {
|
|
725
|
+
v = x.valueConverter.toDb(data[x.key]);
|
|
726
|
+
if (v != undefined) {
|
|
727
|
+
if (!added)
|
|
728
|
+
added = true;
|
|
729
|
+
else {
|
|
730
|
+
cols += ', ';
|
|
731
|
+
vals += ', ';
|
|
732
|
+
}
|
|
733
|
+
cols += e.$dbNameOf(x);
|
|
734
|
+
vals += (0, filter_consumer_bridge_to_sql_request_js_1.toDbSql)(r, x, v);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
845
737
|
}
|
|
846
738
|
}
|
|
847
|
-
catch (
|
|
739
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
848
740
|
finally {
|
|
849
741
|
try {
|
|
850
742
|
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
851
743
|
}
|
|
852
|
-
finally { if (
|
|
853
|
-
}
|
|
854
|
-
colSql = '';
|
|
855
|
-
vals = '';
|
|
856
|
-
for (i = 0; i < cols.length; i++) {
|
|
857
|
-
if (i)
|
|
858
|
-
colSql += ', ';
|
|
859
|
-
colSql += e.$dbNameOf(cols[i]);
|
|
860
|
-
}
|
|
861
|
-
for (i = 0; i < batch.length; i++) {
|
|
862
|
-
if (i)
|
|
863
|
-
vals += ',';
|
|
864
|
-
vals += '(';
|
|
865
|
-
for (j = 0; j < cols.length; j++) {
|
|
866
|
-
if (j)
|
|
867
|
-
vals += ', ';
|
|
868
|
-
x = cols[j];
|
|
869
|
-
v = x.valueConverter.toDb(batch[i][x.key]);
|
|
870
|
-
if (v != undefined)
|
|
871
|
-
vals += (0, filter_consumer_bridge_to_sql_request_js_1.toDbSql)(r, x, v);
|
|
872
|
-
else if (x.allowNull)
|
|
873
|
-
vals += 'null';
|
|
874
|
-
else
|
|
875
|
-
vals += 'DEFAULT';
|
|
876
|
-
}
|
|
877
|
-
vals += ')';
|
|
744
|
+
finally { if (e_6) throw e_6.error; }
|
|
878
745
|
}
|
|
879
|
-
statement = "insert into ".concat(e.$entityName, " (").concat(
|
|
746
|
+
statement = "insert into ".concat(e.$entityName, " (").concat(cols, ") values (").concat(vals, ")");
|
|
880
747
|
return [4 /*yield*/, this.buildSelect(e, r, undefined, undefined)];
|
|
881
|
-
case 1:
|
|
882
|
-
_c = _f.sent(), colKeys = _c.colKeys, select = _c.select;
|
|
883
|
-
source = this.sql._getSourceSql();
|
|
884
|
-
wantRows = (options === null || options === void 0 ? void 0 : options.select) !== 'none';
|
|
885
|
-
if (!source.doesNotSupportReturningSyntax && wantRows)
|
|
886
|
-
statement += ' returning ' + select;
|
|
887
|
-
return [4 /*yield*/, r.execute(statement)];
|
|
888
748
|
case 2:
|
|
889
|
-
|
|
890
|
-
(
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
if (
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
where: filter_interfaces_js_1.Filter.fromEntityFilter(this.entity, (_a = this.entity.idMetadata).getIdFilter.apply(_a, tslib_1.__spreadArray([], tslib_1.__read(ids), false))),
|
|
920
|
-
})];
|
|
921
|
-
case 1:
|
|
922
|
-
found = _b.sent();
|
|
923
|
-
byId = new Map(found.map(function (row) { return [_this.entity.idMetadata.getId(row) + '', row]; }));
|
|
924
|
-
return [2 /*return*/, ids.map(function (id) {
|
|
925
|
-
var row = byId.get(id + '');
|
|
926
|
-
if (!row)
|
|
927
|
-
throw new Error("Failed to insert row - result contained ".concat(found.length, " rows"));
|
|
928
|
-
return row;
|
|
749
|
+
_c = _e.sent(), colKeys = _c.colKeys, select = _c.select;
|
|
750
|
+
if (!this.sql._getSourceSql().doesNotSupportReturningSyntax &&
|
|
751
|
+
!((options === null || options === void 0 ? void 0 : options.select) === 'none'))
|
|
752
|
+
statement += ' returning ' + select;
|
|
753
|
+
return [4 /*yield*/, r.execute(statement).then(function (sql) {
|
|
754
|
+
var _a, _b;
|
|
755
|
+
(_b = (_a = _this.sql._getSourceSql()).afterMutation) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
756
|
+
if (_this.sql._getSourceSql().doesNotSupportReturningSyntax) {
|
|
757
|
+
if ((0, RepositoryImplementation_js_1.isAutoIncrement)(_this.entity.idMetadata.field)) {
|
|
758
|
+
var id_1 = sql.rows[0];
|
|
759
|
+
if (typeof id_1 !== 'number')
|
|
760
|
+
throw new Error('Auto increment, for a database that is does not support returning syntax, should return an array with the single last added id. Instead it returned: ' +
|
|
761
|
+
JSON.stringify(id_1));
|
|
762
|
+
if ((options === null || options === void 0 ? void 0 : options.select) === 'none')
|
|
763
|
+
return undefined;
|
|
764
|
+
return _this.find({
|
|
765
|
+
where: new filter_interfaces_js_1.Filter(function (x) {
|
|
766
|
+
return x.isEqualTo(_this.entity.idMetadata.field, id_1);
|
|
767
|
+
}),
|
|
768
|
+
}).then(function (r) { return r[0]; });
|
|
769
|
+
}
|
|
770
|
+
else {
|
|
771
|
+
if ((options === null || options === void 0 ? void 0 : options.select) === 'none')
|
|
772
|
+
return undefined;
|
|
773
|
+
return getRowAfterUpdate(_this.entity, _this, data, undefined, 'insert');
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
if ((options === null || options === void 0 ? void 0 : options.select) === 'none')
|
|
777
|
+
return undefined;
|
|
778
|
+
return _this.buildResultRow(colKeys, sql.rows[0], sql);
|
|
929
779
|
})];
|
|
780
|
+
case 3: return [2 /*return*/, _e.sent()];
|
|
930
781
|
}
|
|
931
782
|
});
|
|
932
783
|
});
|
|
@@ -962,7 +813,7 @@ function getRowAfterUpdate(meta, dataProvider, data, id, operation) {
|
|
|
962
813
|
return dataProvider
|
|
963
814
|
.find({
|
|
964
815
|
where: new filter_interfaces_js_1.Filter(function (x) {
|
|
965
|
-
var
|
|
816
|
+
var e_7, _a;
|
|
966
817
|
var _b;
|
|
967
818
|
try {
|
|
968
819
|
for (var _c = tslib_1.__values(meta.idMetadata.fields), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
@@ -970,12 +821,12 @@ function getRowAfterUpdate(meta, dataProvider, data, id, operation) {
|
|
|
970
821
|
x.isEqualTo(field, (_b = data[field.key]) !== null && _b !== void 0 ? _b : idFilter[field.key]);
|
|
971
822
|
}
|
|
972
823
|
}
|
|
973
|
-
catch (
|
|
824
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
974
825
|
finally {
|
|
975
826
|
try {
|
|
976
827
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
977
828
|
}
|
|
978
|
-
finally { if (
|
|
829
|
+
finally { if (e_7) throw e_7.error; }
|
|
979
830
|
}
|
|
980
831
|
}),
|
|
981
832
|
})
|
|
@@ -992,8 +843,8 @@ function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
|
|
|
992
843
|
? "count (distinct ".concat(dbName, ")")
|
|
993
844
|
: "".concat(operator, "( ").concat(dbName, " )");
|
|
994
845
|
}
|
|
995
|
-
var select, groupBy, groupByCols, processResultRow,
|
|
996
|
-
var
|
|
846
|
+
var select, groupBy, groupByCols, processResultRow, _loop_1, _a, _b, x, _loop_2, GroupByOperators_1, GroupByOperators_1_1, operator, e_8_1, where, _c, orderBy, _d, _e, x, field, _f, e_9_1, page, result;
|
|
847
|
+
var e_10, _g, e_8, _h, e_9, _j;
|
|
997
848
|
return tslib_1.__generator(this, function (_k) {
|
|
998
849
|
switch (_k.label) {
|
|
999
850
|
case 0:
|
|
@@ -1005,7 +856,7 @@ function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
|
|
|
1005
856
|
theResult[remult3_js_1.GroupByCountMember] = Number(sqlVal);
|
|
1006
857
|
});
|
|
1007
858
|
if (options === null || options === void 0 ? void 0 : options.group) {
|
|
1008
|
-
|
|
859
|
+
_loop_1 = function (x) {
|
|
1009
860
|
if (x.isServerExpression) {
|
|
1010
861
|
}
|
|
1011
862
|
else {
|
|
@@ -1026,26 +877,26 @@ function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
|
|
|
1026
877
|
try {
|
|
1027
878
|
for (_a = tslib_1.__values(options === null || options === void 0 ? void 0 : options.group), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
1028
879
|
x = _b.value;
|
|
1029
|
-
|
|
880
|
+
_loop_1(x);
|
|
1030
881
|
}
|
|
1031
882
|
}
|
|
1032
|
-
catch (
|
|
883
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
1033
884
|
finally {
|
|
1034
885
|
try {
|
|
1035
886
|
if (_b && !_b.done && (_g = _a.return)) _g.call(_a);
|
|
1036
887
|
}
|
|
1037
|
-
finally { if (
|
|
888
|
+
finally { if (e_10) throw e_10.error; }
|
|
1038
889
|
}
|
|
1039
890
|
}
|
|
1040
|
-
|
|
1041
|
-
var fields,
|
|
1042
|
-
var
|
|
891
|
+
_loop_2 = function (operator) {
|
|
892
|
+
var fields, _loop_3, fields_1, fields_1_1, x, e_11_1;
|
|
893
|
+
var e_11, _l;
|
|
1043
894
|
return tslib_1.__generator(this, function (_m) {
|
|
1044
895
|
switch (_m.label) {
|
|
1045
896
|
case 0:
|
|
1046
897
|
fields = options === null || options === void 0 ? void 0 : options[operator];
|
|
1047
898
|
if (!fields) return [3 /*break*/, 8];
|
|
1048
|
-
|
|
899
|
+
_loop_3 = function (x) {
|
|
1049
900
|
var dbName, turnToNumber;
|
|
1050
901
|
return tslib_1.__generator(this, function (_o) {
|
|
1051
902
|
switch (_o.label) {
|
|
@@ -1074,12 +925,12 @@ function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
|
|
|
1074
925
|
_m.label = 1;
|
|
1075
926
|
case 1:
|
|
1076
927
|
_m.trys.push([1, 6, 7, 8]);
|
|
1077
|
-
fields_1 = (
|
|
928
|
+
fields_1 = (e_11 = void 0, tslib_1.__values(fields)), fields_1_1 = fields_1.next();
|
|
1078
929
|
_m.label = 2;
|
|
1079
930
|
case 2:
|
|
1080
931
|
if (!!fields_1_1.done) return [3 /*break*/, 5];
|
|
1081
932
|
x = fields_1_1.value;
|
|
1082
|
-
return [5 /*yield**/,
|
|
933
|
+
return [5 /*yield**/, _loop_3(x)];
|
|
1083
934
|
case 3:
|
|
1084
935
|
_m.sent();
|
|
1085
936
|
_m.label = 4;
|
|
@@ -1088,14 +939,14 @@ function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
|
|
|
1088
939
|
return [3 /*break*/, 2];
|
|
1089
940
|
case 5: return [3 /*break*/, 8];
|
|
1090
941
|
case 6:
|
|
1091
|
-
|
|
1092
|
-
|
|
942
|
+
e_11_1 = _m.sent();
|
|
943
|
+
e_11 = { error: e_11_1 };
|
|
1093
944
|
return [3 /*break*/, 8];
|
|
1094
945
|
case 7:
|
|
1095
946
|
try {
|
|
1096
947
|
if (fields_1_1 && !fields_1_1.done && (_l = fields_1.return)) _l.call(fields_1);
|
|
1097
948
|
}
|
|
1098
|
-
finally { if (
|
|
949
|
+
finally { if (e_11) throw e_11.error; }
|
|
1099
950
|
return [7 /*endfinally*/];
|
|
1100
951
|
case 8: return [2 /*return*/];
|
|
1101
952
|
}
|
|
@@ -1109,7 +960,7 @@ function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
|
|
|
1109
960
|
case 2:
|
|
1110
961
|
if (!!GroupByOperators_1_1.done) return [3 /*break*/, 5];
|
|
1111
962
|
operator = GroupByOperators_1_1.value;
|
|
1112
|
-
return [5 /*yield**/,
|
|
963
|
+
return [5 /*yield**/, _loop_2(operator)];
|
|
1113
964
|
case 3:
|
|
1114
965
|
_k.sent();
|
|
1115
966
|
_k.label = 4;
|
|
@@ -1118,14 +969,14 @@ function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
|
|
|
1118
969
|
return [3 /*break*/, 2];
|
|
1119
970
|
case 5: return [3 /*break*/, 8];
|
|
1120
971
|
case 6:
|
|
1121
|
-
|
|
1122
|
-
|
|
972
|
+
e_8_1 = _k.sent();
|
|
973
|
+
e_8 = { error: e_8_1 };
|
|
1123
974
|
return [3 /*break*/, 8];
|
|
1124
975
|
case 7:
|
|
1125
976
|
try {
|
|
1126
977
|
if (GroupByOperators_1_1 && !GroupByOperators_1_1.done && (_h = GroupByOperators_1.return)) _h.call(GroupByOperators_1);
|
|
1127
978
|
}
|
|
1128
|
-
finally { if (
|
|
979
|
+
finally { if (e_8) throw e_8.error; }
|
|
1129
980
|
return [7 /*endfinally*/];
|
|
1130
981
|
case 8:
|
|
1131
982
|
select += '\n from ' + e.$entityName;
|
|
@@ -1186,14 +1037,14 @@ function groupByImpl(options, e, r, orderByNullFirst, limitSyntax) {
|
|
|
1186
1037
|
return [3 /*break*/, 12];
|
|
1187
1038
|
case 16: return [3 /*break*/, 19];
|
|
1188
1039
|
case 17:
|
|
1189
|
-
|
|
1190
|
-
|
|
1040
|
+
e_9_1 = _k.sent();
|
|
1041
|
+
e_9 = { error: e_9_1 };
|
|
1191
1042
|
return [3 /*break*/, 19];
|
|
1192
1043
|
case 18:
|
|
1193
1044
|
try {
|
|
1194
1045
|
if (_e && !_e.done && (_j = _d.return)) _j.call(_d);
|
|
1195
1046
|
}
|
|
1196
|
-
finally { if (
|
|
1047
|
+
finally { if (e_9) throw e_9.error; }
|
|
1197
1048
|
return [7 /*endfinally*/];
|
|
1198
1049
|
case 19:
|
|
1199
1050
|
if (orderBy)
|