remult 3.4.1 → 3.5.0-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/internals.js +1 -0
- package/esm/postgres/postgres-data-provider.js +4 -5
- package/esm/remult-duckdb.js +4 -0
- package/esm/remult-knex/index.js +41 -9
- package/esm/remult-mongo.js +27 -9
- package/esm/remult-sqlite-core.js +4 -1
- package/esm/server/remult-api-server.js +1 -1
- package/esm/src/buildRestDataProvider.js +4 -2
- package/esm/src/data-api.js +2 -2
- package/esm/src/data-interfaces.js +2 -1
- package/esm/src/data-providers/array-entity-data-provider.js +5 -0
- package/esm/src/data-providers/rest-data-provider-using-fetch.js +2 -2
- package/esm/src/data-providers/retry.js +11 -6
- package/esm/src/data-providers/sql-database.js +41 -31
- package/esm/src/filter/entityDbName.js +6 -10
- package/esm/src/filter/fieldDbName.js +8 -14
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +4 -4
- package/esm/src/filter/sqlExpressionInProgress.js +14 -0
- package/esm/src/live-query/SubscriptionChannel.js +13 -8
- package/esm/src/remult-static.js +1 -0
- package/esm/src/remult3/Fields.js +14 -14
- package/esm/src/remult3/QueryResultImpl.js +2 -0
- package/esm/src/remult3/RepositoryImplementation.js +47 -33
- package/esm/src/sort.js +18 -0
- package/index.d.ts +1 -1
- package/internals.d.ts +1 -0
- package/internals.js +3 -1
- package/package.json +41 -1
- package/postgres/postgres-data-provider.d.ts +2 -3
- package/postgres/postgres-data-provider.js +4 -4
- package/remult-duckdb.d.ts +2 -0
- package/remult-duckdb.js +4 -0
- package/remult-knex/index.d.ts +2 -0
- package/remult-knex/index.js +127 -80
- package/remult-mongo.js +29 -8
- package/remult-sqlite-core.d.ts +2 -1
- package/remult-sqlite-core.js +4 -0
- package/server/remult-api-server.d.ts +12 -1
- package/server/remult-api-server.js +1 -1
- package/src/buildRestDataProvider.js +3 -1
- package/src/column-interfaces.d.ts +5 -1
- package/src/data-api.js +2 -2
- package/src/data-interfaces.d.ts +0 -1
- package/src/data-interfaces.js +3 -0
- package/src/data-providers/array-entity-data-provider.js +5 -0
- package/src/data-providers/rest-data-provider-using-fetch.js +1 -1
- package/src/data-providers/retry.d.ts +4 -1
- package/src/data-providers/retry.js +26 -16
- package/src/data-providers/sql-database.d.ts +7 -3
- package/src/data-providers/sql-database.js +100 -84
- package/src/filter/entityDbName.d.ts +1 -1
- package/src/filter/entityDbName.js +14 -16
- package/src/filter/fieldDbName.js +19 -25
- package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +1 -1
- package/src/filter/filter-consumer-bridge-to-sql-request.js +7 -5
- package/src/filter/sqlExpressionInProgress.d.ts +2 -0
- package/src/filter/sqlExpressionInProgress.js +27 -0
- package/src/live-query/SubscriptionChannel.js +16 -10
- package/src/remult-static.d.ts +2 -0
- package/src/remult-static.js +1 -0
- package/src/remult3/Fields.d.ts +5 -3
- package/src/remult3/Fields.js +24 -13
- package/src/remult3/QueryResultImpl.js +2 -0
- package/src/remult3/RepositoryImplementation.js +284 -272
- package/src/remult3/remult3.d.ts +6 -1
- package/src/sort.d.ts +19 -0
- package/src/sort.js +20 -1
- package/src/sql-command.d.ts +2 -1
package/remult-knex/index.js
CHANGED
|
@@ -74,6 +74,39 @@ var KnexDataProvider = /** @class */ (function () {
|
|
|
74
74
|
throw 'the data provider is not an KnexDataProvider';
|
|
75
75
|
return r.knex;
|
|
76
76
|
};
|
|
77
|
+
Object.defineProperty(KnexDataProvider.prototype, "nativeNullSort", {
|
|
78
|
+
// By `driverName`, as CockroachDB shares the `postgresql` dialect.
|
|
79
|
+
get: function () {
|
|
80
|
+
switch (this.knex.client.driverName) {
|
|
81
|
+
case 'pg':
|
|
82
|
+
case 'pgnative':
|
|
83
|
+
case 'pg-redshift':
|
|
84
|
+
case 'oracledb':
|
|
85
|
+
return {
|
|
86
|
+
order: { asc: 'NULLS LAST', desc: 'NULLS FIRST' },
|
|
87
|
+
syntax: 'NULLS FIRST/LAST',
|
|
88
|
+
};
|
|
89
|
+
case 'mysql':
|
|
90
|
+
case 'mysql2':
|
|
91
|
+
case 'mssql':
|
|
92
|
+
return {
|
|
93
|
+
order: { asc: 'NULLS FIRST', desc: 'NULLS LAST' },
|
|
94
|
+
syntax: 'CASE WHEN',
|
|
95
|
+
};
|
|
96
|
+
case 'sqlite3':
|
|
97
|
+
case 'better-sqlite3':
|
|
98
|
+
case 'cockroachdb':
|
|
99
|
+
return {
|
|
100
|
+
order: { asc: 'NULLS FIRST', desc: 'NULLS LAST' },
|
|
101
|
+
syntax: 'NULLS FIRST/LAST',
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
// `case when` runs on any SQL database.
|
|
105
|
+
return { order: 'unknown', syntax: 'CASE WHEN' };
|
|
106
|
+
},
|
|
107
|
+
enumerable: false,
|
|
108
|
+
configurable: true
|
|
109
|
+
});
|
|
77
110
|
Object.defineProperty(KnexDataProvider.prototype, "jsonColumnStorage", {
|
|
78
111
|
get: function () {
|
|
79
112
|
if (!supportsJsonLoadingAndSaving(this.knex))
|
|
@@ -185,9 +218,9 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
185
218
|
case 0:
|
|
186
219
|
_a = sql_database_js_1.groupByImpl;
|
|
187
220
|
_b = [options];
|
|
188
|
-
return [4 /*yield*/, (0,
|
|
221
|
+
return [4 /*yield*/, (0, filter_consumer_bridge_to_sql_request_js_1.dbNamesOfWithForceSqlExpression)(this.entity, this.dp.wrapIdentifier, true)];
|
|
189
222
|
case 1: return [2 /*return*/, _a.apply(void 0, _b.concat([_c.sent(), this.dp.createCommand(),
|
|
190
|
-
|
|
223
|
+
this.dp.nativeNullSort,
|
|
191
224
|
function (limit, offset) {
|
|
192
225
|
var _a;
|
|
193
226
|
return ((_a = _this.knex.client.config.client) === null || _a === void 0 ? void 0 : _a.includes('mssql'))
|
|
@@ -236,14 +269,14 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
236
269
|
};
|
|
237
270
|
KnexEntityDataProvider.prototype.find = function (options) {
|
|
238
271
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
239
|
-
var e, cols, colKeys, _a, _b, x, name_1, query, br, r_1, r;
|
|
240
|
-
var e_1,
|
|
272
|
+
var e, cols, colKeys, _a, _b, x, name_1, query, br, r_1, native, _c, _d, s, r;
|
|
273
|
+
var e_1, _e, e_2, _f;
|
|
241
274
|
var _this = this;
|
|
242
|
-
return tslib_1.__generator(this, function (
|
|
243
|
-
switch (
|
|
275
|
+
return tslib_1.__generator(this, function (_g) {
|
|
276
|
+
switch (_g.label) {
|
|
244
277
|
case 0: return [4 /*yield*/, this.init()];
|
|
245
278
|
case 1:
|
|
246
|
-
e =
|
|
279
|
+
e = _g.sent();
|
|
247
280
|
cols = [];
|
|
248
281
|
colKeys = [];
|
|
249
282
|
try {
|
|
@@ -265,7 +298,7 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
265
298
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
266
299
|
finally {
|
|
267
300
|
try {
|
|
268
|
-
if (_b && !_b.done && (
|
|
301
|
+
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
269
302
|
}
|
|
270
303
|
finally { if (e_1) throw e_1.error; }
|
|
271
304
|
}
|
|
@@ -275,18 +308,29 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
275
308
|
options.where.__applyToConsumer(br);
|
|
276
309
|
return [4 /*yield*/, br.resolveWhere()];
|
|
277
310
|
case 2:
|
|
278
|
-
r_1 =
|
|
311
|
+
r_1 = _g.sent();
|
|
279
312
|
query.where(function (b) { return r_1.forEach(function (y) { return y(b); }); });
|
|
280
|
-
|
|
313
|
+
_g.label = 3;
|
|
281
314
|
case 3:
|
|
282
315
|
if (!options.orderBy) {
|
|
283
316
|
options.orderBy = sort_js_1.Sort.createUniqueSort(this.entity, new sort_js_1.Sort());
|
|
284
317
|
}
|
|
285
318
|
if (options.orderBy) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
319
|
+
native = this.dp.nativeNullSort;
|
|
320
|
+
try {
|
|
321
|
+
// Not Knex's own `nulls` option: outside Postgres it sorts on `(x is null)` alone.
|
|
322
|
+
for (_c = tslib_1.__values(options.orderBy.Segments), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
323
|
+
s = _d.value;
|
|
324
|
+
query = query.orderByRaw((0, sql_database_js_1.orderBySql)(':column:', s.isDescending, s.field.allowNull, native), { column: e.$dbNameOf(s.field) });
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
328
|
+
finally {
|
|
329
|
+
try {
|
|
330
|
+
if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
|
|
331
|
+
}
|
|
332
|
+
finally { if (e_2) throw e_2.error; }
|
|
333
|
+
}
|
|
290
334
|
}
|
|
291
335
|
if (options.limit) {
|
|
292
336
|
query = query.limit(options.limit);
|
|
@@ -295,7 +339,7 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
295
339
|
}
|
|
296
340
|
return [4 /*yield*/, query];
|
|
297
341
|
case 4:
|
|
298
|
-
r =
|
|
342
|
+
r = _g.sent();
|
|
299
343
|
return [2 /*return*/, r.map(function (y) {
|
|
300
344
|
var result = {};
|
|
301
345
|
var i = 0;
|
|
@@ -320,7 +364,7 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
320
364
|
var _this = this;
|
|
321
365
|
return tslib_1.__generator(this, function (_a) {
|
|
322
366
|
switch (_a.label) {
|
|
323
|
-
case 0: return [4 /*yield*/, (0, filter_consumer_bridge_to_sql_request_js_1.dbNamesOfWithForceSqlExpression)(this.entity, function (x) { return x; })];
|
|
367
|
+
case 0: return [4 /*yield*/, (0, filter_consumer_bridge_to_sql_request_js_1.dbNamesOfWithForceSqlExpression)(this.entity, function (x) { return x; }, true)];
|
|
324
368
|
case 1:
|
|
325
369
|
r = (_a.sent());
|
|
326
370
|
return [2 /*return*/, {
|
|
@@ -339,8 +383,8 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
339
383
|
};
|
|
340
384
|
KnexEntityDataProvider.prototype.update = function (id, data, options) {
|
|
341
385
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
342
|
-
var e, f, updateObject, _a, _b, x, v, key,
|
|
343
|
-
var
|
|
386
|
+
var e, f, updateObject, _a, _b, x, v, key, e_3_1, where;
|
|
387
|
+
var e_3, _c;
|
|
344
388
|
return tslib_1.__generator(this, function (_d) {
|
|
345
389
|
switch (_d.label) {
|
|
346
390
|
case 0: return [4 /*yield*/, this.init()];
|
|
@@ -373,14 +417,14 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
373
417
|
return [3 /*break*/, 3];
|
|
374
418
|
case 7: return [3 /*break*/, 10];
|
|
375
419
|
case 8:
|
|
376
|
-
|
|
377
|
-
|
|
420
|
+
e_3_1 = _d.sent();
|
|
421
|
+
e_3 = { error: e_3_1 };
|
|
378
422
|
return [3 /*break*/, 10];
|
|
379
423
|
case 9:
|
|
380
424
|
try {
|
|
381
425
|
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
382
426
|
}
|
|
383
|
-
finally { if (
|
|
427
|
+
finally { if (e_3) throw e_3.error; }
|
|
384
428
|
return [7 /*endfinally*/];
|
|
385
429
|
case 10: return [4 /*yield*/, f.resolveWhere()];
|
|
386
430
|
case 11:
|
|
@@ -426,8 +470,8 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
426
470
|
};
|
|
427
471
|
KnexEntityDataProvider.prototype.insert = function (data, options) {
|
|
428
472
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
429
|
-
var result_1, data_1, data_1_1, row, _a, _b,
|
|
430
|
-
var
|
|
473
|
+
var result_1, data_1, data_1_1, row, _a, _b, e_4_1, e, batches, result, batches_1, batches_1_1, batch, _c, _d, _e, _f, e_5_1;
|
|
474
|
+
var e_4, _g, e_5, _h;
|
|
431
475
|
var _this = this;
|
|
432
476
|
return tslib_1.__generator(this, function (_j) {
|
|
433
477
|
switch (_j.label) {
|
|
@@ -456,14 +500,14 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
456
500
|
return [3 /*break*/, 2];
|
|
457
501
|
case 5: return [3 /*break*/, 8];
|
|
458
502
|
case 6:
|
|
459
|
-
|
|
460
|
-
|
|
503
|
+
e_4_1 = _j.sent();
|
|
504
|
+
e_4 = { error: e_4_1 };
|
|
461
505
|
return [3 /*break*/, 8];
|
|
462
506
|
case 7:
|
|
463
507
|
try {
|
|
464
508
|
if (data_1_1 && !data_1_1.done && (_g = data_1.return)) _g.call(data_1);
|
|
465
509
|
}
|
|
466
|
-
finally { if (
|
|
510
|
+
finally { if (e_4) throw e_4.error; }
|
|
467
511
|
return [7 /*endfinally*/];
|
|
468
512
|
case 8: return [2 /*return*/, result_1];
|
|
469
513
|
case 9: return [4 /*yield*/, this.init()];
|
|
@@ -493,14 +537,14 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
493
537
|
return [3 /*break*/, 12];
|
|
494
538
|
case 15: return [3 /*break*/, 18];
|
|
495
539
|
case 16:
|
|
496
|
-
|
|
497
|
-
|
|
540
|
+
e_5_1 = _j.sent();
|
|
541
|
+
e_5 = { error: e_5_1 };
|
|
498
542
|
return [3 /*break*/, 18];
|
|
499
543
|
case 17:
|
|
500
544
|
try {
|
|
501
545
|
if (batches_1_1 && !batches_1_1.done && (_h = batches_1.return)) _h.call(batches_1);
|
|
502
546
|
}
|
|
503
|
-
finally { if (
|
|
547
|
+
finally { if (e_5) throw e_5.error; }
|
|
504
548
|
return [7 /*endfinally*/];
|
|
505
549
|
case 18: return [2 /*return*/, result];
|
|
506
550
|
}
|
|
@@ -509,8 +553,8 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
509
553
|
};
|
|
510
554
|
KnexEntityDataProvider.prototype.insertBatch = function (batch, e, options) {
|
|
511
555
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
512
|
-
var cols, _loop_1, _a, _b, x, insertObjects, batch_1, batch_1_1, row, insertObject, cols_1, cols_1_1, x, v, key,
|
|
513
|
-
var
|
|
556
|
+
var cols, _loop_1, _a, _b, x, insertObjects, batch_1, batch_1_1, row, insertObject, cols_1, cols_1_1, x, v, key, e_6_1, e_7_1, insert, wantRows, result, ids;
|
|
557
|
+
var e_8, _c, e_7, _d, e_6, _e;
|
|
514
558
|
var _this = this;
|
|
515
559
|
return tslib_1.__generator(this, function (_f) {
|
|
516
560
|
switch (_f.label) {
|
|
@@ -530,12 +574,12 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
530
574
|
_loop_1(x);
|
|
531
575
|
}
|
|
532
576
|
}
|
|
533
|
-
catch (
|
|
577
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
534
578
|
finally {
|
|
535
579
|
try {
|
|
536
580
|
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
537
581
|
}
|
|
538
|
-
finally { if (
|
|
582
|
+
finally { if (e_8) throw e_8.error; }
|
|
539
583
|
}
|
|
540
584
|
insertObjects = [];
|
|
541
585
|
_f.label = 1;
|
|
@@ -550,7 +594,7 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
550
594
|
_f.label = 3;
|
|
551
595
|
case 3:
|
|
552
596
|
_f.trys.push([3, 8, 9, 10]);
|
|
553
|
-
cols_1 = (
|
|
597
|
+
cols_1 = (e_6 = void 0, tslib_1.__values(cols)), cols_1_1 = cols_1.next();
|
|
554
598
|
_f.label = 4;
|
|
555
599
|
case 4:
|
|
556
600
|
if (!!cols_1_1.done) return [3 /*break*/, 7];
|
|
@@ -571,14 +615,14 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
571
615
|
return [3 /*break*/, 4];
|
|
572
616
|
case 7: return [3 /*break*/, 10];
|
|
573
617
|
case 8:
|
|
574
|
-
|
|
575
|
-
|
|
618
|
+
e_6_1 = _f.sent();
|
|
619
|
+
e_6 = { error: e_6_1 };
|
|
576
620
|
return [3 /*break*/, 10];
|
|
577
621
|
case 9:
|
|
578
622
|
try {
|
|
579
623
|
if (cols_1_1 && !cols_1_1.done && (_e = cols_1.return)) _e.call(cols_1);
|
|
580
624
|
}
|
|
581
|
-
finally { if (
|
|
625
|
+
finally { if (e_6) throw e_6.error; }
|
|
582
626
|
return [7 /*endfinally*/];
|
|
583
627
|
case 10:
|
|
584
628
|
insertObjects.push(insertObject);
|
|
@@ -588,14 +632,14 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
588
632
|
return [3 /*break*/, 2];
|
|
589
633
|
case 12: return [3 /*break*/, 15];
|
|
590
634
|
case 13:
|
|
591
|
-
|
|
592
|
-
|
|
635
|
+
e_7_1 = _f.sent();
|
|
636
|
+
e_7 = { error: e_7_1 };
|
|
593
637
|
return [3 /*break*/, 15];
|
|
594
638
|
case 14:
|
|
595
639
|
try {
|
|
596
640
|
if (batch_1_1 && !batch_1_1.done && (_d = batch_1.return)) _d.call(batch_1);
|
|
597
641
|
}
|
|
598
|
-
finally { if (
|
|
642
|
+
finally { if (e_7) throw e_7.error; }
|
|
599
643
|
return [7 /*endfinally*/];
|
|
600
644
|
case 15:
|
|
601
645
|
insert = this.getEntityFrom(e).insert(insertObjects);
|
|
@@ -644,8 +688,8 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
644
688
|
//@internal
|
|
645
689
|
KnexEntityDataProvider.prototype.insertOne = function (data, options) {
|
|
646
690
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
647
|
-
var e, insertObject, _a, _b, x, v, key,
|
|
648
|
-
var
|
|
691
|
+
var e, insertObject, _a, _b, x, v, key, e_9_1, insert, newId_1, result, result;
|
|
692
|
+
var e_9, _c;
|
|
649
693
|
var _this = this;
|
|
650
694
|
return tslib_1.__generator(this, function (_d) {
|
|
651
695
|
switch (_d.label) {
|
|
@@ -676,14 +720,14 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
676
720
|
return [3 /*break*/, 3];
|
|
677
721
|
case 7: return [3 /*break*/, 10];
|
|
678
722
|
case 8:
|
|
679
|
-
|
|
680
|
-
|
|
723
|
+
e_9_1 = _d.sent();
|
|
724
|
+
e_9 = { error: e_9_1 };
|
|
681
725
|
return [3 /*break*/, 10];
|
|
682
726
|
case 9:
|
|
683
727
|
try {
|
|
684
728
|
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
685
729
|
}
|
|
686
|
-
finally { if (
|
|
730
|
+
finally { if (e_9) throw e_9.error; }
|
|
687
731
|
return [7 /*endfinally*/];
|
|
688
732
|
case 10:
|
|
689
733
|
insert = this.getEntityFrom(e).insert(insertObject);
|
|
@@ -734,8 +778,8 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
734
778
|
}
|
|
735
779
|
FilterConsumerBridgeToKnexRequest.prototype.resolveWhere = function () {
|
|
736
780
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
737
|
-
var p, p_1, p_1_1, pr,
|
|
738
|
-
var
|
|
781
|
+
var p, p_1, p_1_1, pr, e_10_1;
|
|
782
|
+
var e_10, _a;
|
|
739
783
|
return tslib_1.__generator(this, function (_b) {
|
|
740
784
|
switch (_b.label) {
|
|
741
785
|
case 0:
|
|
@@ -745,7 +789,7 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
745
789
|
_b.label = 1;
|
|
746
790
|
case 1:
|
|
747
791
|
_b.trys.push([1, 6, 7, 8]);
|
|
748
|
-
p_1 = (
|
|
792
|
+
p_1 = (e_10 = void 0, tslib_1.__values(p)), p_1_1 = p_1.next();
|
|
749
793
|
_b.label = 2;
|
|
750
794
|
case 2:
|
|
751
795
|
if (!!p_1_1.done) return [3 /*break*/, 5];
|
|
@@ -759,14 +803,14 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
759
803
|
return [3 /*break*/, 2];
|
|
760
804
|
case 5: return [3 /*break*/, 8];
|
|
761
805
|
case 6:
|
|
762
|
-
|
|
763
|
-
|
|
806
|
+
e_10_1 = _b.sent();
|
|
807
|
+
e_10 = { error: e_10_1 };
|
|
764
808
|
return [3 /*break*/, 8];
|
|
765
809
|
case 7:
|
|
766
810
|
try {
|
|
767
811
|
if (p_1_1 && !p_1_1.done && (_a = p_1.return)) _a.call(p_1);
|
|
768
812
|
}
|
|
769
|
-
finally { if (
|
|
813
|
+
finally { if (e_10) throw e_10.error; }
|
|
770
814
|
return [7 /*endfinally*/];
|
|
771
815
|
case 8: return [3 /*break*/, 0];
|
|
772
816
|
case 9: return [2 /*return*/, this.result];
|
|
@@ -780,8 +824,8 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
780
824
|
FilterConsumerBridgeToKnexRequest.prototype.or = function (orElements) {
|
|
781
825
|
var _this = this;
|
|
782
826
|
this.promises.push((function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
783
|
-
var result, _loop_2, this_1, orElements_1, orElements_1_1, element, state_1,
|
|
784
|
-
var
|
|
827
|
+
var result, _loop_2, this_1, orElements_1, orElements_1_1, element, state_1, e_11_1;
|
|
828
|
+
var e_11, _a;
|
|
785
829
|
return tslib_1.__generator(this, function (_b) {
|
|
786
830
|
switch (_b.label) {
|
|
787
831
|
case 0:
|
|
@@ -830,14 +874,14 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
830
874
|
return [3 /*break*/, 2];
|
|
831
875
|
case 5: return [3 /*break*/, 8];
|
|
832
876
|
case 6:
|
|
833
|
-
|
|
834
|
-
|
|
877
|
+
e_11_1 = _b.sent();
|
|
878
|
+
e_11 = { error: e_11_1 };
|
|
835
879
|
return [3 /*break*/, 8];
|
|
836
880
|
case 7:
|
|
837
881
|
try {
|
|
838
882
|
if (orElements_1_1 && !orElements_1_1.done && (_a = orElements_1.return)) _a.call(orElements_1);
|
|
839
883
|
}
|
|
840
|
-
finally { if (
|
|
884
|
+
finally { if (e_11) throw e_11.error; }
|
|
841
885
|
return [7 /*endfinally*/];
|
|
842
886
|
case 8:
|
|
843
887
|
if (result.length > 0) {
|
|
@@ -983,8 +1027,8 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
983
1027
|
}
|
|
984
1028
|
KnexSchemaBuilder.prototype.ensureSchema = function (entities) {
|
|
985
1029
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
986
|
-
var entities_1, entities_1_1, entity, e, err_2,
|
|
987
|
-
var
|
|
1030
|
+
var entities_1, entities_1_1, entity, e, err_2, e_12_1;
|
|
1031
|
+
var e_12, _a;
|
|
988
1032
|
return tslib_1.__generator(this, function (_b) {
|
|
989
1033
|
switch (_b.label) {
|
|
990
1034
|
case 0:
|
|
@@ -1018,14 +1062,14 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
1018
1062
|
return [3 /*break*/, 1];
|
|
1019
1063
|
case 9: return [3 /*break*/, 12];
|
|
1020
1064
|
case 10:
|
|
1021
|
-
|
|
1022
|
-
|
|
1065
|
+
e_12_1 = _b.sent();
|
|
1066
|
+
e_12 = { error: e_12_1 };
|
|
1023
1067
|
return [3 /*break*/, 12];
|
|
1024
1068
|
case 11:
|
|
1025
1069
|
try {
|
|
1026
1070
|
if (entities_1_1 && !entities_1_1.done && (_a = entities_1.return)) _a.call(entities_1);
|
|
1027
1071
|
}
|
|
1028
|
-
finally { if (
|
|
1072
|
+
finally { if (e_12) throw e_12.error; }
|
|
1029
1073
|
return [7 /*endfinally*/];
|
|
1030
1074
|
case 12: return [2 /*return*/];
|
|
1031
1075
|
}
|
|
@@ -1053,7 +1097,7 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
1053
1097
|
});
|
|
1054
1098
|
};
|
|
1055
1099
|
KnexSchemaBuilder.prototype.createTableKnexCommand = function (entity, e) {
|
|
1056
|
-
var
|
|
1100
|
+
var e_13, _a;
|
|
1057
1101
|
var _this = this;
|
|
1058
1102
|
var cols = new Map();
|
|
1059
1103
|
try {
|
|
@@ -1065,15 +1109,15 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
1065
1109
|
});
|
|
1066
1110
|
}
|
|
1067
1111
|
}
|
|
1068
|
-
catch (
|
|
1112
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
1069
1113
|
finally {
|
|
1070
1114
|
try {
|
|
1071
1115
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1072
1116
|
}
|
|
1073
|
-
finally { if (
|
|
1117
|
+
finally { if (e_13) throw e_13.error; }
|
|
1074
1118
|
}
|
|
1075
1119
|
return this.knex.schema.createTable(e.$entityName, function (b) {
|
|
1076
|
-
var
|
|
1120
|
+
var e_14, _a;
|
|
1077
1121
|
try {
|
|
1078
1122
|
for (var _b = tslib_1.__values(entity.fields), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1079
1123
|
var x = _c.value;
|
|
@@ -1086,12 +1130,12 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
1086
1130
|
}
|
|
1087
1131
|
}
|
|
1088
1132
|
}
|
|
1089
|
-
catch (
|
|
1133
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
1090
1134
|
finally {
|
|
1091
1135
|
try {
|
|
1092
1136
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1093
1137
|
}
|
|
1094
|
-
finally { if (
|
|
1138
|
+
finally { if (e_14) throw e_14.error; }
|
|
1095
1139
|
}
|
|
1096
1140
|
b.primary(entity.idMetadata.fields.map(function (f) { return e.$dbNameOf(f); }));
|
|
1097
1141
|
});
|
|
@@ -1128,8 +1172,8 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
1128
1172
|
};
|
|
1129
1173
|
KnexSchemaBuilder.prototype.verifyAllColumns = function (entity) {
|
|
1130
1174
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1131
|
-
var e, _loop_3, this_2, _a, _b, col,
|
|
1132
|
-
var
|
|
1175
|
+
var e, _loop_3, this_2, _a, _b, col, e_15_1, err_3;
|
|
1176
|
+
var e_15, _c;
|
|
1133
1177
|
return tslib_1.__generator(this, function (_d) {
|
|
1134
1178
|
switch (_d.label) {
|
|
1135
1179
|
case 0: return [4 /*yield*/, (0, filter_consumer_bridge_to_sql_request_js_2.dbNamesOf)(entity, function (x) { return x; })];
|
|
@@ -1169,14 +1213,14 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
1169
1213
|
return [3 /*break*/, 4];
|
|
1170
1214
|
case 7: return [3 /*break*/, 10];
|
|
1171
1215
|
case 8:
|
|
1172
|
-
|
|
1173
|
-
|
|
1216
|
+
e_15_1 = _d.sent();
|
|
1217
|
+
e_15 = { error: e_15_1 };
|
|
1174
1218
|
return [3 /*break*/, 10];
|
|
1175
1219
|
case 9:
|
|
1176
1220
|
try {
|
|
1177
1221
|
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1178
1222
|
}
|
|
1179
|
-
finally { if (
|
|
1223
|
+
finally { if (e_15) throw e_15.error; }
|
|
1180
1224
|
return [7 /*endfinally*/];
|
|
1181
1225
|
case 10: return [3 /*break*/, 12];
|
|
1182
1226
|
case 11:
|
|
@@ -1222,8 +1266,11 @@ function buildColumn(x, dbName, b, supportsJson) {
|
|
|
1222
1266
|
c.defaultTo(0).notNullable();
|
|
1223
1267
|
}
|
|
1224
1268
|
}
|
|
1225
|
-
else
|
|
1226
|
-
b.specificType(dbName, x.valueConverter.fieldTypeInDb);
|
|
1269
|
+
else {
|
|
1270
|
+
var c = b.specificType(dbName, x.valueConverter.fieldTypeInDb);
|
|
1271
|
+
if (!x.allowNull)
|
|
1272
|
+
c.defaultTo(0).notNullable();
|
|
1273
|
+
}
|
|
1227
1274
|
}
|
|
1228
1275
|
else if (x.valueType == Date) {
|
|
1229
1276
|
if (!x.valueConverter.fieldTypeInDb)
|
|
@@ -1302,7 +1349,7 @@ function knexMaxParametersInOneSqlStatement(knex) {
|
|
|
1302
1349
|
return defaultMaxParametersInOneSqlStatement;
|
|
1303
1350
|
}
|
|
1304
1351
|
function splitByMaxParameters(items, parametersInItem, maxParameters) {
|
|
1305
|
-
var
|
|
1352
|
+
var e_16, _a;
|
|
1306
1353
|
var batches = [];
|
|
1307
1354
|
var batch = [];
|
|
1308
1355
|
var params = 0;
|
|
@@ -1319,19 +1366,19 @@ function splitByMaxParameters(items, parametersInItem, maxParameters) {
|
|
|
1319
1366
|
params += n;
|
|
1320
1367
|
}
|
|
1321
1368
|
}
|
|
1322
|
-
catch (
|
|
1369
|
+
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
1323
1370
|
finally {
|
|
1324
1371
|
try {
|
|
1325
1372
|
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
|
|
1326
1373
|
}
|
|
1327
|
-
finally { if (
|
|
1374
|
+
finally { if (e_16) throw e_16.error; }
|
|
1328
1375
|
}
|
|
1329
1376
|
if (batch.length)
|
|
1330
1377
|
batches.push(batch);
|
|
1331
1378
|
return batches;
|
|
1332
1379
|
}
|
|
1333
1380
|
function countKnexInsertBindParameters(entity, e, row, storage) {
|
|
1334
|
-
var
|
|
1381
|
+
var e_17, _a;
|
|
1335
1382
|
var n = 0;
|
|
1336
1383
|
try {
|
|
1337
1384
|
for (var _b = tslib_1.__values(entity.fields), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -1343,12 +1390,12 @@ function countKnexInsertBindParameters(entity, e, row, storage) {
|
|
|
1343
1390
|
n++;
|
|
1344
1391
|
}
|
|
1345
1392
|
}
|
|
1346
|
-
catch (
|
|
1393
|
+
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
1347
1394
|
finally {
|
|
1348
1395
|
try {
|
|
1349
1396
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1350
1397
|
}
|
|
1351
|
-
finally { if (
|
|
1398
|
+
finally { if (e_17) throw e_17.error; }
|
|
1352
1399
|
}
|
|
1353
1400
|
return n;
|
|
1354
1401
|
}
|
package/remult-mongo.js
CHANGED
|
@@ -10,6 +10,18 @@ var RepositoryImplementation_js_1 = require("./src/remult3/RepositoryImplementat
|
|
|
10
10
|
var repository_internals_js_1 = require("./src/remult3/repository-internals.js");
|
|
11
11
|
var sql_database_js_1 = require("./src/data-providers/sql-database.js");
|
|
12
12
|
var remult3_js_1 = require("./src/remult3/remult3.js");
|
|
13
|
+
var sort_js_1 = require("./src/sort.js");
|
|
14
|
+
var nullSortWarned = false;
|
|
15
|
+
// `$sort` has no NULL option, so Mongo sorts NULL lowest whatever NullSort says.
|
|
16
|
+
function warnIfNullSortIgnored() {
|
|
17
|
+
var order = sort_js_1.NullSort.order;
|
|
18
|
+
if (nullSortWarned || order === 'native')
|
|
19
|
+
return;
|
|
20
|
+
if (order.asc === 'NULLS FIRST' && order.desc === 'NULLS LAST')
|
|
21
|
+
return;
|
|
22
|
+
nullSortWarned = true;
|
|
23
|
+
console.warn('[remult] NullSort is ignored on Mongo, which sorts NULL lowest: paginator() can skip or repeat rows');
|
|
24
|
+
}
|
|
13
25
|
var MongoDataProvider = /** @class */ (function () {
|
|
14
26
|
function MongoDataProvider(db, client, options) {
|
|
15
27
|
this.db = db;
|
|
@@ -135,7 +147,13 @@ var MongoDataProvider = /** @class */ (function () {
|
|
|
135
147
|
return MongoDataProvider;
|
|
136
148
|
}());
|
|
137
149
|
exports.MongoDataProvider = MongoDataProvider;
|
|
150
|
+
// Older versions wrote NULL as this marker, which sorts above numbers and strings.
|
|
138
151
|
var NULL = { $null: '$null' };
|
|
152
|
+
// `$in: [null, NULL]` fails: Mongo cannot nest `$` under `$in`.
|
|
153
|
+
function nullFilter(name) {
|
|
154
|
+
var _a, _b;
|
|
155
|
+
return { $or: [(_a = {}, _a[name] = null, _a), (_b = {}, _b[name] = { $eq: NULL }, _b)] };
|
|
156
|
+
}
|
|
139
157
|
function isNull(x) {
|
|
140
158
|
return (x === null || x === void 0 ? void 0 : x.$null) === NULL.$null;
|
|
141
159
|
}
|
|
@@ -230,10 +248,7 @@ var MongoEntityDataProvider = /** @class */ (function () {
|
|
|
230
248
|
var col = _c.value;
|
|
231
249
|
if (col.dbReadOnly || col.isServerExpression)
|
|
232
250
|
continue;
|
|
233
|
-
|
|
234
|
-
if (val === null)
|
|
235
|
-
val = NULL;
|
|
236
|
-
result[nameProvider.$dbNameOf(col)] = val;
|
|
251
|
+
result[nameProvider.$dbNameOf(col)] = toDb(col, row[col.key]);
|
|
237
252
|
}
|
|
238
253
|
}
|
|
239
254
|
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
@@ -365,6 +380,7 @@ var MongoEntityDataProvider = /** @class */ (function () {
|
|
|
365
380
|
finally { if (e_6) throw e_6.error; }
|
|
366
381
|
}
|
|
367
382
|
if (options === null || options === void 0 ? void 0 : options.orderBy) {
|
|
383
|
+
warnIfNullSortIgnored();
|
|
368
384
|
sort = {};
|
|
369
385
|
try {
|
|
370
386
|
for (_d = tslib_1.__values(options.orderBy), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
@@ -452,6 +468,7 @@ var MongoEntityDataProvider = /** @class */ (function () {
|
|
|
452
468
|
}
|
|
453
469
|
}
|
|
454
470
|
if (options.orderBy) {
|
|
471
|
+
warnIfNullSortIgnored();
|
|
455
472
|
op.sort = {};
|
|
456
473
|
try {
|
|
457
474
|
for (_b = tslib_1.__values(options.orderBy.Segments), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -619,7 +636,7 @@ var MongoEntityDataProvider = /** @class */ (function () {
|
|
|
619
636
|
var e, collection;
|
|
620
637
|
return tslib_1.__generator(this, function (_a) {
|
|
621
638
|
switch (_a.label) {
|
|
622
|
-
case 0: return [4 /*yield*/, (0, filter_consumer_bridge_to_sql_request_js_1.
|
|
639
|
+
case 0: return [4 /*yield*/, (0, filter_consumer_bridge_to_sql_request_js_1.dbNamesOfWithForceSqlExpression)(this.entity, undefined, true)];
|
|
623
640
|
case 1:
|
|
624
641
|
e = _a.sent();
|
|
625
642
|
collection = this.db.collection(e.$entityName);
|
|
@@ -764,10 +781,14 @@ var FilterConsumerBridgeToMongo = /** @class */ (function () {
|
|
|
764
781
|
}); })());
|
|
765
782
|
};
|
|
766
783
|
FilterConsumerBridgeToMongo.prototype.isNull = function (col) {
|
|
767
|
-
|
|
784
|
+
var _this = this;
|
|
785
|
+
this.result.push(function () { return nullFilter(_this.nameProvider.$dbNameOf(col)); });
|
|
768
786
|
};
|
|
769
787
|
FilterConsumerBridgeToMongo.prototype.isNotNull = function (col) {
|
|
770
|
-
|
|
788
|
+
var _this = this;
|
|
789
|
+
this.result.push(function () { return ({
|
|
790
|
+
$nor: [nullFilter(_this.nameProvider.$dbNameOf(col))],
|
|
791
|
+
}); });
|
|
771
792
|
};
|
|
772
793
|
FilterConsumerBridgeToMongo.prototype.isIn = function (col, val) {
|
|
773
794
|
var _this = this;
|
|
@@ -831,7 +852,7 @@ var FilterConsumerBridgeToMongo = /** @class */ (function () {
|
|
|
831
852
|
this.result.push(function () {
|
|
832
853
|
var _a, _b;
|
|
833
854
|
return (_a = {},
|
|
834
|
-
_a[_this.nameProvider.$dbNameOf(col)] = tslib_1.__assign((_b = {}, _b[operator] =
|
|
855
|
+
_a[_this.nameProvider.$dbNameOf(col)] = tslib_1.__assign((_b = {}, _b[operator] = toDb(col, val), _b), moreOptions),
|
|
835
856
|
_a);
|
|
836
857
|
});
|
|
837
858
|
};
|
package/remult-sqlite-core.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { EntityMetadata } from './src/remult3/remult3.js';
|
|
2
|
+
import type { NativeNullSort } from './src/sort.js';
|
|
2
3
|
import type { SqlCommand, SqlImplementation } from './src/sql-command.js';
|
|
3
4
|
import type { FieldMetadata } from './src/column-interfaces.js';
|
|
4
5
|
import type { CanBuildMigrations, MigrationBuilder, MigrationCode } from './migrations/migration-types.js';
|
|
@@ -8,7 +9,7 @@ export declare class SqliteCoreDataProvider implements SqlImplementation, CanBui
|
|
|
8
9
|
doesNotSupportReturningSyntax: boolean;
|
|
9
10
|
doesNotSupportReturningSyntaxOnlyForUpdate: boolean;
|
|
10
11
|
constructor(createCommand: () => SqlCommand, end: () => Promise<void>, doesNotSupportReturningSyntax?: boolean, doesNotSupportReturningSyntaxOnlyForUpdate?: boolean);
|
|
11
|
-
|
|
12
|
+
nativeNullSort: NativeNullSort;
|
|
12
13
|
maxParametersInOneSqlStatement: number;
|
|
13
14
|
getLimitSqlSyntax(limit: number, offset: number): string;
|
|
14
15
|
afterMutation?: VoidFunction;
|
package/remult-sqlite-core.js
CHANGED
|
@@ -13,6 +13,10 @@ var SqliteCoreDataProvider = /** @class */ (function () {
|
|
|
13
13
|
this.end = end;
|
|
14
14
|
this.doesNotSupportReturningSyntax = doesNotSupportReturningSyntax;
|
|
15
15
|
this.doesNotSupportReturningSyntaxOnlyForUpdate = doesNotSupportReturningSyntaxOnlyForUpdate;
|
|
16
|
+
this.nativeNullSort = {
|
|
17
|
+
order: { asc: 'NULLS FIRST', desc: 'NULLS LAST' },
|
|
18
|
+
syntax: 'NULLS FIRST/LAST',
|
|
19
|
+
};
|
|
16
20
|
this.maxParametersInOneSqlStatement = 999;
|
|
17
21
|
}
|
|
18
22
|
SqliteCoreDataProvider.prototype.getLimitSqlSyntax = function (limit, offset) {
|