remult 3.4.2 → 3.5.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/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 +69 -14
- package/esm/remult-mongo.js +25 -7
- package/esm/remult-sqlite-core.js +4 -1
- package/esm/server/remult-api-server.js +14 -6
- package/esm/src/buildRestDataProvider.js +8 -6
- package/esm/src/context.js +1 -1
- 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 +9 -4
- package/esm/src/data-providers/rest-data-provider-using-fetch.js +13 -6
- package/esm/src/data-providers/retry.js +11 -6
- package/esm/src/data-providers/sql-database.js +40 -30
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +35 -4
- package/esm/src/filter/filter-interfaces.js +18 -4
- package/esm/src/live-query/SubscriptionChannel.js +13 -8
- package/esm/src/remult-proxy.js +12 -0
- package/esm/src/remult-static.js +2 -0
- package/esm/src/remult3/Fields.js +14 -14
- package/esm/src/remult3/RepositoryImplementation.js +69 -32
- package/esm/src/remult3/remult3.js +2 -0
- package/esm/src/server-action.js +43 -14
- package/esm/src/sort.js +18 -0
- package/index.d.ts +4 -3
- 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 +153 -83
- package/remult-mongo.js +28 -7
- package/remult-sqlite-core.d.ts +2 -1
- package/remult-sqlite-core.js +4 -0
- package/server/remult-api-server.d.ts +28 -1
- package/server/remult-api-server.js +19 -12
- package/src/buildRestDataProvider.d.ts +1 -1
- package/src/buildRestDataProvider.js +8 -6
- package/src/column-interfaces.d.ts +5 -1
- package/src/context.js +1 -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 +9 -4
- package/src/data-providers/rest-data-provider-using-fetch.d.ts +1 -1
- package/src/data-providers/rest-data-provider-using-fetch.js +11 -4
- 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 +99 -81
- package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +8 -0
- package/src/filter/filter-consumer-bridge-to-sql-request.js +58 -19
- package/src/filter/filter-interfaces.js +19 -2
- package/src/live-query/SubscriptionChannel.js +16 -10
- package/src/remult-proxy.js +28 -0
- package/src/remult-static.d.ts +4 -0
- package/src/remult-static.js +2 -0
- package/src/remult3/Fields.d.ts +5 -3
- package/src/remult3/Fields.js +24 -13
- package/src/remult3/RepositoryImplementation.d.ts +7 -0
- package/src/remult3/RepositoryImplementation.js +325 -264
- package/src/remult3/remult3.d.ts +68 -5
- package/src/remult3/remult3.js +2 -0
- package/src/server-action.d.ts +34 -2
- package/src/server-action.js +195 -115
- package/src/sort.d.ts +19 -0
- package/src/sort.js +20 -1
- package/src/sql-command.d.ts +2 -1
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SqlDatabase = void 0;
|
|
4
4
|
exports.jsonColumnStorageOf = jsonColumnStorageOf;
|
|
5
5
|
exports.getRowAfterUpdate = getRowAfterUpdate;
|
|
6
|
+
exports.orderBySql = orderBySql;
|
|
6
7
|
exports.buildFindSql = buildFindSql;
|
|
7
8
|
exports.groupByImpl = groupByImpl;
|
|
8
9
|
exports.buildGroupBySql = buildGroupBySql;
|
|
@@ -90,6 +91,13 @@ var SqlDatabase = /** @class */ (function () {
|
|
|
90
91
|
enumerable: false,
|
|
91
92
|
configurable: true
|
|
92
93
|
});
|
|
94
|
+
Object.defineProperty(SqlDatabase.prototype, "nativeNullSort", {
|
|
95
|
+
get: function () {
|
|
96
|
+
return this.sql.nativeNullSort;
|
|
97
|
+
},
|
|
98
|
+
enumerable: false,
|
|
99
|
+
configurable: true
|
|
100
|
+
});
|
|
93
101
|
/* @internal*/
|
|
94
102
|
SqlDatabase.prototype._getSourceSql = function () {
|
|
95
103
|
return this.sql;
|
|
@@ -175,7 +183,7 @@ var SqlDatabase = /** @class */ (function () {
|
|
|
175
183
|
end: this.end,
|
|
176
184
|
doesNotSupportReturningSyntax: this.sql.doesNotSupportReturningSyntax,
|
|
177
185
|
doesNotSupportReturningSyntaxOnlyForUpdate: this.sql.doesNotSupportReturningSyntaxOnlyForUpdate,
|
|
178
|
-
|
|
186
|
+
nativeNullSort: this.sql.nativeNullSort,
|
|
179
187
|
afterMutation: this.sql.afterMutation,
|
|
180
188
|
maxParametersInOneSqlStatement: this.sql.maxParametersInOneSqlStatement,
|
|
181
189
|
}))];
|
|
@@ -268,7 +276,7 @@ var SqlDatabase = /** @class */ (function () {
|
|
|
268
276
|
case 3:
|
|
269
277
|
_c = (_h.sent());
|
|
270
278
|
_h.label = 4;
|
|
271
|
-
case 4: return [4 /*yield*/, _a.apply(void 0, _b.concat([_c, (_f = sql === null || sql === void 0 ? void 0 : sql.sqlCommand) !== null && _f !== void 0 ? _f : new myDummySQLCommand(),
|
|
279
|
+
case 4: return [4 /*yield*/, _a.apply(void 0, _b.concat([_c, (_f = sql === null || sql === void 0 ? void 0 : sql.sqlCommand) !== null && _f !== void 0 ? _f : new myDummySQLCommand(), nativeNullSortOf(r), (_g = sql === null || sql === void 0 ? void 0 : sql.limitSyntax) !== null && _g !== void 0 ? _g : limitSyntaxRequired, jsonColumnStorageForRaw(r, sql === null || sql === void 0 ? void 0 : sql.jsonAsString)]))];
|
|
272
280
|
case 5:
|
|
273
281
|
built = _h.sent();
|
|
274
282
|
return [2 /*return*/, {
|
|
@@ -304,7 +312,7 @@ var SqlDatabase = /** @class */ (function () {
|
|
|
304
312
|
case 3:
|
|
305
313
|
_c = (_h.sent());
|
|
306
314
|
_h.label = 4;
|
|
307
|
-
case 4: return [4 /*yield*/, _a.apply(void 0, _b.concat([_c, (_f = sql === null || sql === void 0 ? void 0 : sql.sqlCommand) !== null && _f !== void 0 ? _f : new myDummySQLCommand(),
|
|
315
|
+
case 4: return [4 /*yield*/, _a.apply(void 0, _b.concat([_c, (_f = sql === null || sql === void 0 ? void 0 : sql.sqlCommand) !== null && _f !== void 0 ? _f : new myDummySQLCommand(), nativeNullSortOf(r), (_g = sql === null || sql === void 0 ? void 0 : sql.limitSyntax) !== null && _g !== void 0 ? _g : limitSyntaxRequired, {
|
|
308
316
|
aliasColumns: true,
|
|
309
317
|
jsonColumnStorage: jsonColumnStorageForRaw(r, sql === null || sql === void 0 ? void 0 : sql.jsonAsString),
|
|
310
318
|
}]))];
|
|
@@ -521,7 +529,7 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
|
|
|
521
529
|
_b = [options];
|
|
522
530
|
return [4 /*yield*/, this.init()];
|
|
523
531
|
case 1: return [4 /*yield*/, _a.apply(void 0, _b.concat([_c.sent(), this.sql.createCommand(),
|
|
524
|
-
this.sql.
|
|
532
|
+
this.sql.nativeNullSort,
|
|
525
533
|
this.sql._getSourceSql().getLimitSqlSyntax,
|
|
526
534
|
this.sql.jsonColumnStorage]))];
|
|
527
535
|
case 2: return [2 /*return*/, _c.sent()];
|
|
@@ -541,7 +549,7 @@ var ActualSQLEntityDataProvider = /** @class */ (function () {
|
|
|
541
549
|
r = this.sql.createCommand();
|
|
542
550
|
if (options && !options.orderBy)
|
|
543
551
|
options.orderBy = sort_js_1.Sort.createUniqueSort(this.entity, new sort_js_1.Sort());
|
|
544
|
-
return [4 /*yield*/, buildFindSql(this.entity, options, e, r, this.sql.
|
|
552
|
+
return [4 /*yield*/, buildFindSql(this.entity, options, e, r, this.sql.nativeNullSort, function (limit, offset) { return _this.strategy.getLimitSqlSyntax(limit, offset); }, { jsonColumnStorage: this.sql.jsonColumnStorage })];
|
|
545
553
|
case 2:
|
|
546
554
|
_a = _b.sent(), select = _a.select, toResult = _a.toResult;
|
|
547
555
|
return [4 /*yield*/, r.execute(select)];
|
|
@@ -856,6 +864,13 @@ function wrapIdentifierOf(r) {
|
|
|
856
864
|
return (_a = dp.wrapIdentifier) === null || _a === void 0 ? void 0 : _a.bind(dp);
|
|
857
865
|
return undefined;
|
|
858
866
|
}
|
|
867
|
+
function nativeNullSortOf(r) {
|
|
868
|
+
var dp = (0, repository_internals_js_1.getRepositoryInternals)(r)._dataProvider;
|
|
869
|
+
if ((0, isOfType_js_1.isOfType)(dp, 'nativeNullSort'))
|
|
870
|
+
return dp.nativeNullSort;
|
|
871
|
+
// Not a SQL repo, so the raw select's database is unknown.
|
|
872
|
+
return { order: 'unknown', syntax: 'CASE WHEN' };
|
|
873
|
+
}
|
|
859
874
|
function jsonColumnStorageOf(r) {
|
|
860
875
|
var dp = (0, repository_internals_js_1.getRepositoryInternals)(r)._dataProvider;
|
|
861
876
|
if ((0, isOfType_js_1.isOfType)(dp, 'jsonColumnStorage'))
|
|
@@ -921,17 +936,31 @@ function getRowAfterUpdate(meta, dataProvider, data, id, operation) {
|
|
|
921
936
|
return r[0];
|
|
922
937
|
});
|
|
923
938
|
}
|
|
939
|
+
/** Writes the NULL order only on a nullable column, where NullSort differs from the database's own. */
|
|
940
|
+
function orderBySql(expr, isDescending, nullable, native) {
|
|
941
|
+
var sql = isDescending ? expr + ' desc' : expr;
|
|
942
|
+
if (!nullable || sort_js_1.NullSort.order === 'native')
|
|
943
|
+
return sql;
|
|
944
|
+
var dir = isDescending ? 'desc' : 'asc';
|
|
945
|
+
var nullSort = sort_js_1.NullSort.order[dir];
|
|
946
|
+
if (native.order !== 'unknown' && native.order[dir] === nullSort)
|
|
947
|
+
return sql;
|
|
948
|
+
if (native.syntax === 'NULLS FIRST/LAST')
|
|
949
|
+
return sql + ' ' + nullSort.toLowerCase();
|
|
950
|
+
var _a = tslib_1.__read(nullSort === 'NULLS FIRST' ? [0, 1] : [1, 0], 2), ifNull = _a[0], otherwise = _a[1];
|
|
951
|
+
return "case when ".concat(expr, " is null then ").concat(ifNull, " else ").concat(otherwise, " end, ").concat(sql);
|
|
952
|
+
}
|
|
924
953
|
/** The select that `find` runs, and the mapping of one result row to field values. With `aliasColumns`, every column is aliased through `wrapIdentifier`, so a row can be read by alias as well as by position. */
|
|
925
|
-
function buildFindSql(entity_1, options_1, e_7, r_1,
|
|
926
|
-
return tslib_1.__awaiter(this, arguments, void 0, function (entity, options, e, r,
|
|
927
|
-
var _b, colKeys, columns, select, where, _c, first, _d, _e, c, _f, _g, e_8_1, page;
|
|
928
|
-
var e_8,
|
|
929
|
-
var
|
|
930
|
-
return tslib_1.__generator(this, function (
|
|
931
|
-
switch (
|
|
954
|
+
function buildFindSql(entity_1, options_1, e_7, r_1, nativeNullSort_1, limitSyntax_1) {
|
|
955
|
+
return tslib_1.__awaiter(this, arguments, void 0, function (entity, options, e, r, nativeNullSort, limitSyntax, _a) {
|
|
956
|
+
var _b, colKeys, columns, select, where, _c, first, _d, _e, c, _f, _g, _h, e_8_1, page;
|
|
957
|
+
var e_8, _j;
|
|
958
|
+
var _k = _a === void 0 ? {} : _a, _l = _k.aliasColumns, aliasColumns = _l === void 0 ? false : _l, _m = _k.jsonColumnStorage, jsonColumnStorage = _m === void 0 ? 'native' : _m;
|
|
959
|
+
return tslib_1.__generator(this, function (_o) {
|
|
960
|
+
switch (_o.label) {
|
|
932
961
|
case 0: return [4 /*yield*/, selectColumns(entity, e, r, options === null || options === void 0 ? void 0 : options.select, options === null || options === void 0 ? void 0 : options.args, aliasColumns)];
|
|
933
962
|
case 1:
|
|
934
|
-
_b =
|
|
963
|
+
_b = _o.sent(), colKeys = _b.colKeys, columns = _b.select;
|
|
935
964
|
select = 'select ' + columns + '\n from ' + e.$entityName;
|
|
936
965
|
if (!options) return [3 /*break*/, 14];
|
|
937
966
|
if (!options.where) return [3 /*break*/, 3];
|
|
@@ -940,19 +969,19 @@ function buildFindSql(entity_1, options_1, e_7, r_1, orderByNullsFirst_1, limitS
|
|
|
940
969
|
_c = select;
|
|
941
970
|
return [4 /*yield*/, where.resolveWhere()];
|
|
942
971
|
case 2:
|
|
943
|
-
select = _c +
|
|
944
|
-
|
|
972
|
+
select = _c + _o.sent();
|
|
973
|
+
_o.label = 3;
|
|
945
974
|
case 3:
|
|
946
975
|
if (options.limit) {
|
|
947
976
|
options.orderBy = sort_js_1.Sort.createUniqueSort(entity, options.orderBy);
|
|
948
977
|
}
|
|
949
978
|
if (!options.orderBy) return [3 /*break*/, 13];
|
|
950
979
|
first = true;
|
|
951
|
-
|
|
980
|
+
_o.label = 4;
|
|
952
981
|
case 4:
|
|
953
|
-
|
|
982
|
+
_o.trys.push([4, 11, 12, 13]);
|
|
954
983
|
_d = tslib_1.__values(options.orderBy.Segments), _e = _d.next();
|
|
955
|
-
|
|
984
|
+
_o.label = 5;
|
|
956
985
|
case 5:
|
|
957
986
|
if (!!_e.done) return [3 /*break*/, 10];
|
|
958
987
|
c = _e.value;
|
|
@@ -963,35 +992,30 @@ function buildFindSql(entity_1, options_1, e_7, r_1, orderByNullsFirst_1, limitS
|
|
|
963
992
|
else
|
|
964
993
|
select += ', ';
|
|
965
994
|
_f = select;
|
|
995
|
+
_g = orderBySql;
|
|
966
996
|
if (!c.field.options.sqlExpression) return [3 /*break*/, 6];
|
|
967
|
-
|
|
997
|
+
_h = c.field.key;
|
|
968
998
|
return [3 /*break*/, 8];
|
|
969
999
|
case 6: return [4 /*yield*/, e.$dbNameOf(c.field)];
|
|
970
1000
|
case 7:
|
|
971
|
-
|
|
972
|
-
|
|
1001
|
+
_h = _o.sent();
|
|
1002
|
+
_o.label = 8;
|
|
973
1003
|
case 8:
|
|
974
|
-
select = _f + _g
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
if (c.isDescending)
|
|
979
|
-
select += ' nulls last';
|
|
980
|
-
else
|
|
981
|
-
select += ' nulls first';
|
|
982
|
-
}
|
|
983
|
-
_m.label = 9;
|
|
1004
|
+
select = _f + _g.apply(void 0, [_h, c.isDescending,
|
|
1005
|
+
c.field.allowNull,
|
|
1006
|
+
nativeNullSort]);
|
|
1007
|
+
_o.label = 9;
|
|
984
1008
|
case 9:
|
|
985
1009
|
_e = _d.next();
|
|
986
1010
|
return [3 /*break*/, 5];
|
|
987
1011
|
case 10: return [3 /*break*/, 13];
|
|
988
1012
|
case 11:
|
|
989
|
-
e_8_1 =
|
|
1013
|
+
e_8_1 = _o.sent();
|
|
990
1014
|
e_8 = { error: e_8_1 };
|
|
991
1015
|
return [3 /*break*/, 13];
|
|
992
1016
|
case 12:
|
|
993
1017
|
try {
|
|
994
|
-
if (_e && !_e.done && (
|
|
1018
|
+
if (_e && !_e.done && (_j = _d.return)) _j.call(_d);
|
|
995
1019
|
}
|
|
996
1020
|
finally { if (e_8) throw e_8.error; }
|
|
997
1021
|
return [7 /*endfinally*/];
|
|
@@ -1004,7 +1028,7 @@ function buildFindSql(entity_1, options_1, e_7, r_1, orderByNullsFirst_1, limitS
|
|
|
1004
1028
|
page = 1;
|
|
1005
1029
|
select += ' ' + limitSyntax(options.limit, (page - 1) * options.limit);
|
|
1006
1030
|
}
|
|
1007
|
-
|
|
1031
|
+
_o.label = 14;
|
|
1008
1032
|
case 14: return [2 /*return*/, {
|
|
1009
1033
|
select: select,
|
|
1010
1034
|
colKeys: colKeys,
|
|
@@ -1091,13 +1115,13 @@ function resultRow(colKeys, valueAt, storage) {
|
|
|
1091
1115
|
});
|
|
1092
1116
|
return result;
|
|
1093
1117
|
}
|
|
1094
|
-
function groupByImpl(options_1, e_9, r_1,
|
|
1095
|
-
return tslib_1.__awaiter(this, arguments, void 0, function (options, e, r,
|
|
1118
|
+
function groupByImpl(options_1, e_9, r_1, nativeNullSort_1, limitSyntax_1) {
|
|
1119
|
+
return tslib_1.__awaiter(this, arguments, void 0, function (options, e, r, nativeNullSort, limitSyntax, jsonColumnStorage) {
|
|
1096
1120
|
var _a, select, toResult, result;
|
|
1097
1121
|
if (jsonColumnStorage === void 0) { jsonColumnStorage = 'native'; }
|
|
1098
1122
|
return tslib_1.__generator(this, function (_b) {
|
|
1099
1123
|
switch (_b.label) {
|
|
1100
|
-
case 0: return [4 /*yield*/, buildGroupBySql(options, e, r,
|
|
1124
|
+
case 0: return [4 /*yield*/, buildGroupBySql(options, e, r, nativeNullSort, limitSyntax, jsonColumnStorage)];
|
|
1101
1125
|
case 1:
|
|
1102
1126
|
_a = _b.sent(), select = _a.select, toResult = _a.toResult;
|
|
1103
1127
|
return [4 /*yield*/, r.execute(select)];
|
|
@@ -1111,8 +1135,8 @@ function groupByImpl(options_1, e_9, r_1, orderByNullFirst_1, limitSyntax_1) {
|
|
|
1111
1135
|
});
|
|
1112
1136
|
}
|
|
1113
1137
|
/** The select that `groupBy` runs, and the mapping of one result row back to a `GroupByResult`. Every column is aliased through `wrapIdentifier`, so a row can be read by alias as well as by position. */
|
|
1114
|
-
function buildGroupBySql(options_1, e_9, r_1,
|
|
1115
|
-
return tslib_1.__awaiter(this, arguments, void 0, function (options, e, r,
|
|
1138
|
+
function buildGroupBySql(options_1, e_9, r_1, nativeNullSort_1, limitSyntax_1) {
|
|
1139
|
+
return tslib_1.__awaiter(this, arguments, void 0, function (options, e, r, nativeNullSort, limitSyntax, jsonColumnStorage) {
|
|
1116
1140
|
function alias(name) {
|
|
1117
1141
|
aliases.push(name);
|
|
1118
1142
|
return e.wrapIdentifier(name);
|
|
@@ -1122,11 +1146,12 @@ function buildGroupBySql(options_1, e_9, r_1, orderByNullFirst_1, limitSyntax_1)
|
|
|
1122
1146
|
? "count (distinct ".concat(dbName, ")")
|
|
1123
1147
|
: "".concat(operator, "( ").concat(dbName, " )");
|
|
1124
1148
|
}
|
|
1125
|
-
var aliases, select, groupBy, groupByCols, processResultRow, _loop_2, _a, _b, x, _loop_3, GroupByOperators_1, GroupByOperators_1_1, operator, e_10_1, where, _c, orderBy, _d, _e, x, field, _f, e_11_1, page;
|
|
1149
|
+
var aliases, select, groupBy, groupByCols, processResultRow, _loop_2, _a, _b, x, _loop_3, GroupByOperators_1, GroupByOperators_1_1, operator, e_10_1, where, _c, orderBy, _d, _e, x, field, _f, nullable, e_11_1, page;
|
|
1126
1150
|
var e_12, _g, e_10, _h, e_11, _j;
|
|
1151
|
+
var _k;
|
|
1127
1152
|
if (jsonColumnStorage === void 0) { jsonColumnStorage = 'native'; }
|
|
1128
|
-
return tslib_1.__generator(this, function (
|
|
1129
|
-
switch (
|
|
1153
|
+
return tslib_1.__generator(this, function (_l) {
|
|
1154
|
+
switch (_l.label) {
|
|
1130
1155
|
case 0:
|
|
1131
1156
|
aliases = [];
|
|
1132
1157
|
select = 'select count(*) as ' + alias('count');
|
|
@@ -1169,24 +1194,24 @@ function buildGroupBySql(options_1, e_9, r_1, orderByNullFirst_1, limitSyntax_1)
|
|
|
1169
1194
|
}
|
|
1170
1195
|
_loop_3 = function (operator) {
|
|
1171
1196
|
var fields, _loop_4, fields_1, fields_1_1, x, e_13_1;
|
|
1172
|
-
var e_13,
|
|
1173
|
-
return tslib_1.__generator(this, function (
|
|
1174
|
-
switch (
|
|
1197
|
+
var e_13, _m;
|
|
1198
|
+
return tslib_1.__generator(this, function (_o) {
|
|
1199
|
+
switch (_o.label) {
|
|
1175
1200
|
case 0:
|
|
1176
1201
|
fields = options === null || options === void 0 ? void 0 : options[operator];
|
|
1177
1202
|
if (!fields) return [3 /*break*/, 8];
|
|
1178
1203
|
_loop_4 = function (x) {
|
|
1179
1204
|
var dbName, turnToNumber;
|
|
1180
|
-
return tslib_1.__generator(this, function (
|
|
1181
|
-
switch (
|
|
1205
|
+
return tslib_1.__generator(this, function (_p) {
|
|
1206
|
+
switch (_p.label) {
|
|
1182
1207
|
case 0:
|
|
1183
1208
|
if (!x.isServerExpression) return [3 /*break*/, 1];
|
|
1184
1209
|
return [3 /*break*/, 3];
|
|
1185
1210
|
case 1: return [4 /*yield*/, e.$dbNameOf(x)];
|
|
1186
1211
|
case 2:
|
|
1187
|
-
dbName =
|
|
1212
|
+
dbName = _p.sent();
|
|
1188
1213
|
select += ", ".concat(aggregateSqlSyntax(operator, dbName), " as ").concat(alias(x.key + '_' + operator));
|
|
1189
|
-
|
|
1214
|
+
_p.label = 3;
|
|
1190
1215
|
case 3:
|
|
1191
1216
|
turnToNumber = x.valueType === Number || operator == 'distinctCount';
|
|
1192
1217
|
processResultRow.push(function (sqlResult, theResult) {
|
|
@@ -1201,29 +1226,29 @@ function buildGroupBySql(options_1, e_9, r_1, orderByNullFirst_1, limitSyntax_1)
|
|
|
1201
1226
|
}
|
|
1202
1227
|
});
|
|
1203
1228
|
};
|
|
1204
|
-
|
|
1229
|
+
_o.label = 1;
|
|
1205
1230
|
case 1:
|
|
1206
|
-
|
|
1231
|
+
_o.trys.push([1, 6, 7, 8]);
|
|
1207
1232
|
fields_1 = (e_13 = void 0, tslib_1.__values(fields)), fields_1_1 = fields_1.next();
|
|
1208
|
-
|
|
1233
|
+
_o.label = 2;
|
|
1209
1234
|
case 2:
|
|
1210
1235
|
if (!!fields_1_1.done) return [3 /*break*/, 5];
|
|
1211
1236
|
x = fields_1_1.value;
|
|
1212
1237
|
return [5 /*yield**/, _loop_4(x)];
|
|
1213
1238
|
case 3:
|
|
1214
|
-
|
|
1215
|
-
|
|
1239
|
+
_o.sent();
|
|
1240
|
+
_o.label = 4;
|
|
1216
1241
|
case 4:
|
|
1217
1242
|
fields_1_1 = fields_1.next();
|
|
1218
1243
|
return [3 /*break*/, 2];
|
|
1219
1244
|
case 5: return [3 /*break*/, 8];
|
|
1220
1245
|
case 6:
|
|
1221
|
-
e_13_1 =
|
|
1246
|
+
e_13_1 = _o.sent();
|
|
1222
1247
|
e_13 = { error: e_13_1 };
|
|
1223
1248
|
return [3 /*break*/, 8];
|
|
1224
1249
|
case 7:
|
|
1225
1250
|
try {
|
|
1226
|
-
if (fields_1_1 && !fields_1_1.done && (
|
|
1251
|
+
if (fields_1_1 && !fields_1_1.done && (_m = fields_1.return)) _m.call(fields_1);
|
|
1227
1252
|
}
|
|
1228
1253
|
finally { if (e_13) throw e_13.error; }
|
|
1229
1254
|
return [7 /*endfinally*/];
|
|
@@ -1231,24 +1256,24 @@ function buildGroupBySql(options_1, e_9, r_1, orderByNullFirst_1, limitSyntax_1)
|
|
|
1231
1256
|
}
|
|
1232
1257
|
});
|
|
1233
1258
|
};
|
|
1234
|
-
|
|
1259
|
+
_l.label = 1;
|
|
1235
1260
|
case 1:
|
|
1236
|
-
|
|
1261
|
+
_l.trys.push([1, 6, 7, 8]);
|
|
1237
1262
|
GroupByOperators_1 = tslib_1.__values(remult3_js_1.GroupByOperators), GroupByOperators_1_1 = GroupByOperators_1.next();
|
|
1238
|
-
|
|
1263
|
+
_l.label = 2;
|
|
1239
1264
|
case 2:
|
|
1240
1265
|
if (!!GroupByOperators_1_1.done) return [3 /*break*/, 5];
|
|
1241
1266
|
operator = GroupByOperators_1_1.value;
|
|
1242
1267
|
return [5 /*yield**/, _loop_3(operator)];
|
|
1243
1268
|
case 3:
|
|
1244
|
-
|
|
1245
|
-
|
|
1269
|
+
_l.sent();
|
|
1270
|
+
_l.label = 4;
|
|
1246
1271
|
case 4:
|
|
1247
1272
|
GroupByOperators_1_1 = GroupByOperators_1.next();
|
|
1248
1273
|
return [3 /*break*/, 2];
|
|
1249
1274
|
case 5: return [3 /*break*/, 8];
|
|
1250
1275
|
case 6:
|
|
1251
|
-
e_10_1 =
|
|
1276
|
+
e_10_1 = _l.sent();
|
|
1252
1277
|
e_10 = { error: e_10_1 };
|
|
1253
1278
|
return [3 /*break*/, 8];
|
|
1254
1279
|
case 7:
|
|
@@ -1265,18 +1290,18 @@ function buildGroupBySql(options_1, e_9, r_1, orderByNullFirst_1, limitSyntax_1)
|
|
|
1265
1290
|
_c = select;
|
|
1266
1291
|
return [4 /*yield*/, where.resolveWhere()];
|
|
1267
1292
|
case 9:
|
|
1268
|
-
select = _c +
|
|
1269
|
-
|
|
1293
|
+
select = _c + _l.sent();
|
|
1294
|
+
_l.label = 10;
|
|
1270
1295
|
case 10:
|
|
1271
1296
|
if (groupBy)
|
|
1272
1297
|
select += groupBy;
|
|
1273
1298
|
orderBy = '';
|
|
1274
1299
|
if (!(options === null || options === void 0 ? void 0 : options.orderBy)) return [3 /*break*/, 20];
|
|
1275
|
-
|
|
1300
|
+
_l.label = 11;
|
|
1276
1301
|
case 11:
|
|
1277
|
-
|
|
1302
|
+
_l.trys.push([11, 17, 18, 19]);
|
|
1278
1303
|
_d = tslib_1.__values(options === null || options === void 0 ? void 0 : options.orderBy), _e = _d.next();
|
|
1279
|
-
|
|
1304
|
+
_l.label = 12;
|
|
1280
1305
|
case 12:
|
|
1281
1306
|
if (!!_e.done) return [3 /*break*/, 16];
|
|
1282
1307
|
x = _e.value;
|
|
@@ -1288,8 +1313,8 @@ function buildGroupBySql(options_1, e_9, r_1, orderByNullFirst_1, limitSyntax_1)
|
|
|
1288
1313
|
if (!_f) return [3 /*break*/, 14];
|
|
1289
1314
|
return [4 /*yield*/, e.$dbNameOf(x.field)];
|
|
1290
1315
|
case 13:
|
|
1291
|
-
_f = (
|
|
1292
|
-
|
|
1316
|
+
_f = (_l.sent());
|
|
1317
|
+
_l.label = 14;
|
|
1293
1318
|
case 14:
|
|
1294
1319
|
field = _f;
|
|
1295
1320
|
switch (x.operation) {
|
|
@@ -1301,22 +1326,15 @@ function buildGroupBySql(options_1, e_9, r_1, orderByNullFirst_1, limitSyntax_1)
|
|
|
1301
1326
|
default:
|
|
1302
1327
|
field = aggregateSqlSyntax(x.operation, field);
|
|
1303
1328
|
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
if (orderByNullFirst) {
|
|
1308
|
-
if (x.isDescending)
|
|
1309
|
-
orderBy += ' nulls last';
|
|
1310
|
-
else
|
|
1311
|
-
orderBy += ' nulls first';
|
|
1312
|
-
}
|
|
1313
|
-
_k.label = 15;
|
|
1329
|
+
nullable = !!((_k = x.field) === null || _k === void 0 ? void 0 : _k.allowNull) && x.operation !== 'distinctCount';
|
|
1330
|
+
orderBy += orderBySql(field, x.isDescending, nullable, nativeNullSort);
|
|
1331
|
+
_l.label = 15;
|
|
1314
1332
|
case 15:
|
|
1315
1333
|
_e = _d.next();
|
|
1316
1334
|
return [3 /*break*/, 12];
|
|
1317
1335
|
case 16: return [3 /*break*/, 19];
|
|
1318
1336
|
case 17:
|
|
1319
|
-
e_11_1 =
|
|
1337
|
+
e_11_1 = _l.sent();
|
|
1320
1338
|
e_11 = { error: e_11_1 };
|
|
1321
1339
|
return [3 /*break*/, 19];
|
|
1322
1340
|
case 18:
|
|
@@ -1328,7 +1346,7 @@ function buildGroupBySql(options_1, e_9, r_1, orderByNullFirst_1, limitSyntax_1)
|
|
|
1328
1346
|
case 19:
|
|
1329
1347
|
if (orderBy)
|
|
1330
1348
|
select += orderBy;
|
|
1331
|
-
|
|
1349
|
+
_l.label = 20;
|
|
1332
1350
|
case 20:
|
|
1333
1351
|
// Skip paging for a pure aggregate (single row); OFFSET/FETCH without an
|
|
1334
1352
|
// ORDER BY is also invalid on SQL Server.
|
|
@@ -5,6 +5,13 @@ import type { HasWrapIdentifier, JsonColumnStorage, SqlCommandWithParameters } f
|
|
|
5
5
|
import type { Filter, FilterConsumer } from './filter-interfaces.js';
|
|
6
6
|
export declare const LIKE_ESCAPE_SQL = " escape '!'";
|
|
7
7
|
export declare function escapeLike(val: string): string;
|
|
8
|
+
/** `$not` uses `case when` once the predicate mentions a column that allows null. */
|
|
9
|
+
export declare class HandleNull {
|
|
10
|
+
nullable: boolean;
|
|
11
|
+
add(other: HandleNull): void;
|
|
12
|
+
column(col: FieldMetadata): void;
|
|
13
|
+
custom(): void;
|
|
14
|
+
}
|
|
8
15
|
export declare class FilterConsumerBridgeToSqlRequest implements FilterConsumer {
|
|
9
16
|
private r;
|
|
10
17
|
private nameProvider;
|
|
@@ -12,6 +19,7 @@ export declare class FilterConsumerBridgeToSqlRequest implements FilterConsumer
|
|
|
12
19
|
private where;
|
|
13
20
|
_addWhere: boolean;
|
|
14
21
|
promises: Promise<void>[];
|
|
22
|
+
handleNull: HandleNull;
|
|
15
23
|
resolveWhere(): Promise<string>;
|
|
16
24
|
constructor(r: SqlCommandWithParameters, nameProvider: EntityDbNamesBase, jsonColumnStorage?: JsonColumnStorage);
|
|
17
25
|
custom(key: string, customItem: any): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CustomSqlFilterBuilder = exports.FilterConsumerBridgeToSqlRequest = exports.LIKE_ESCAPE_SQL = void 0;
|
|
3
|
+
exports.CustomSqlFilterBuilder = exports.FilterConsumerBridgeToSqlRequest = exports.HandleNull = exports.LIKE_ESCAPE_SQL = void 0;
|
|
4
4
|
exports.escapeLike = escapeLike;
|
|
5
5
|
exports.isDbReadonly = isDbReadonly;
|
|
6
6
|
exports.shouldNotCreateField = shouldNotCreateField;
|
|
@@ -24,6 +24,25 @@ exports.LIKE_ESCAPE_SQL = " escape '!'";
|
|
|
24
24
|
function escapeLike(val) {
|
|
25
25
|
return val.replace(REGEX_LIKE_SPECIAL, '!$&');
|
|
26
26
|
}
|
|
27
|
+
/** `$not` uses `case when` once the predicate mentions a column that allows null. */
|
|
28
|
+
var HandleNull = /** @class */ (function () {
|
|
29
|
+
function HandleNull() {
|
|
30
|
+
this.nullable = false;
|
|
31
|
+
}
|
|
32
|
+
HandleNull.prototype.add = function (other) {
|
|
33
|
+
if (other.nullable)
|
|
34
|
+
this.nullable = true;
|
|
35
|
+
};
|
|
36
|
+
HandleNull.prototype.column = function (col) {
|
|
37
|
+
if (col.allowNull)
|
|
38
|
+
this.nullable = true;
|
|
39
|
+
};
|
|
40
|
+
HandleNull.prototype.custom = function () {
|
|
41
|
+
this.nullable = true;
|
|
42
|
+
};
|
|
43
|
+
return HandleNull;
|
|
44
|
+
}());
|
|
45
|
+
exports.HandleNull = HandleNull;
|
|
27
46
|
var FilterConsumerBridgeToSqlRequest = /** @class */ (function () {
|
|
28
47
|
function FilterConsumerBridgeToSqlRequest(r, nameProvider, jsonColumnStorage) {
|
|
29
48
|
if (jsonColumnStorage === void 0) { jsonColumnStorage = 'native'; }
|
|
@@ -33,6 +52,7 @@ var FilterConsumerBridgeToSqlRequest = /** @class */ (function () {
|
|
|
33
52
|
this.where = '';
|
|
34
53
|
this._addWhere = true;
|
|
35
54
|
this.promises = [];
|
|
55
|
+
this.handleNull = new HandleNull();
|
|
36
56
|
}
|
|
37
57
|
FilterConsumerBridgeToSqlRequest.prototype.resolveWhere = function () {
|
|
38
58
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
@@ -81,28 +101,32 @@ var FilterConsumerBridgeToSqlRequest = /** @class */ (function () {
|
|
|
81
101
|
};
|
|
82
102
|
FilterConsumerBridgeToSqlRequest.prototype.or = function (orElements) {
|
|
83
103
|
var _this = this;
|
|
84
|
-
var statement = '';
|
|
85
104
|
this.promises.push((function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
86
|
-
var orElements_1, orElements_1_1, element, f, where, e_2_1;
|
|
105
|
+
var statement, branches, orElements_1, orElements_1_1, element, f, where, e_2_1;
|
|
87
106
|
var e_2, _a;
|
|
88
107
|
return tslib_1.__generator(this, function (_b) {
|
|
89
108
|
switch (_b.label) {
|
|
90
109
|
case 0:
|
|
91
|
-
|
|
92
|
-
|
|
110
|
+
statement = '';
|
|
111
|
+
branches = new HandleNull();
|
|
93
112
|
_b.label = 1;
|
|
94
113
|
case 1:
|
|
95
|
-
|
|
114
|
+
_b.trys.push([1, 6, 7, 8]);
|
|
115
|
+
orElements_1 = tslib_1.__values(orElements), orElements_1_1 = orElements_1.next();
|
|
116
|
+
_b.label = 2;
|
|
117
|
+
case 2:
|
|
118
|
+
if (!!orElements_1_1.done) return [3 /*break*/, 5];
|
|
96
119
|
element = orElements_1_1.value;
|
|
97
120
|
f = new FilterConsumerBridgeToSqlRequest(this.r, this.nameProvider, this.jsonColumnStorage);
|
|
98
121
|
f._addWhere = false;
|
|
99
122
|
element.__applyToConsumer(f);
|
|
100
123
|
return [4 /*yield*/, f.resolveWhere()];
|
|
101
|
-
case
|
|
124
|
+
case 3:
|
|
102
125
|
where = _b.sent();
|
|
103
126
|
if (!where)
|
|
104
127
|
return [2 /*return*/]; //since if any member of or is empty, then the entire or is irrelevant
|
|
105
128
|
if (where.length > 0) {
|
|
129
|
+
branches.add(f.handleNull);
|
|
106
130
|
if (statement.length > 0) {
|
|
107
131
|
statement += ' or ';
|
|
108
132
|
}
|
|
@@ -112,22 +136,23 @@ var FilterConsumerBridgeToSqlRequest = /** @class */ (function () {
|
|
|
112
136
|
else
|
|
113
137
|
statement += where;
|
|
114
138
|
}
|
|
115
|
-
_b.label =
|
|
116
|
-
case
|
|
139
|
+
_b.label = 4;
|
|
140
|
+
case 4:
|
|
117
141
|
orElements_1_1 = orElements_1.next();
|
|
118
|
-
return [3 /*break*/,
|
|
119
|
-
case
|
|
120
|
-
case
|
|
142
|
+
return [3 /*break*/, 2];
|
|
143
|
+
case 5: return [3 /*break*/, 8];
|
|
144
|
+
case 6:
|
|
121
145
|
e_2_1 = _b.sent();
|
|
122
146
|
e_2 = { error: e_2_1 };
|
|
123
|
-
return [3 /*break*/,
|
|
124
|
-
case
|
|
147
|
+
return [3 /*break*/, 8];
|
|
148
|
+
case 7:
|
|
125
149
|
try {
|
|
126
150
|
if (orElements_1_1 && !orElements_1_1.done && (_a = orElements_1.return)) _a.call(orElements_1);
|
|
127
151
|
}
|
|
128
152
|
finally { if (e_2) throw e_2.error; }
|
|
129
153
|
return [7 /*endfinally*/];
|
|
130
|
-
case
|
|
154
|
+
case 8:
|
|
155
|
+
this.handleNull.add(branches);
|
|
131
156
|
this.addToWhere('(' + statement + ')');
|
|
132
157
|
return [2 /*return*/];
|
|
133
158
|
}
|
|
@@ -144,12 +169,19 @@ var FilterConsumerBridgeToSqlRequest = /** @class */ (function () {
|
|
|
144
169
|
f = new FilterConsumerBridgeToSqlRequest(this.r, this.nameProvider, this.jsonColumnStorage);
|
|
145
170
|
f._addWhere = false;
|
|
146
171
|
element.__applyToConsumer(f);
|
|
147
|
-
return [4 /*yield*/, f.resolveWhere()
|
|
172
|
+
return [4 /*yield*/, f.resolveWhere()
|
|
173
|
+
// An empty filter matches every row, so its not matches none.
|
|
174
|
+
];
|
|
148
175
|
case 1:
|
|
149
176
|
where = _a.sent();
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
177
|
+
// An empty filter matches every row, so its not matches none.
|
|
178
|
+
if (!where) {
|
|
179
|
+
this.addToWhere('1 = 0');
|
|
180
|
+
return [2 /*return*/];
|
|
181
|
+
}
|
|
182
|
+
this.addToWhere(f.handleNull.nullable
|
|
183
|
+
? 'case when (' + where + ') then 0 else 1 end = 1'
|
|
184
|
+
: 'not (' + where + ')');
|
|
153
185
|
return [2 /*return*/];
|
|
154
186
|
}
|
|
155
187
|
});
|
|
@@ -157,18 +189,22 @@ var FilterConsumerBridgeToSqlRequest = /** @class */ (function () {
|
|
|
157
189
|
};
|
|
158
190
|
FilterConsumerBridgeToSqlRequest.prototype.isNull = function (col) {
|
|
159
191
|
var _this = this;
|
|
192
|
+
this.handleNull.column(col);
|
|
160
193
|
this.promises.push((function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
161
194
|
return [2 /*return*/, this.addToWhere(this.nameProvider.$dbNameOf(col) + ' is null')];
|
|
162
195
|
}); }); })());
|
|
163
196
|
};
|
|
164
197
|
FilterConsumerBridgeToSqlRequest.prototype.isNotNull = function (col) {
|
|
165
198
|
var _this = this;
|
|
199
|
+
this.handleNull.column(col);
|
|
166
200
|
this.promises.push((function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
167
201
|
return [2 /*return*/, this.addToWhere(this.nameProvider.$dbNameOf(col) + ' is not null')];
|
|
168
202
|
}); }); })());
|
|
169
203
|
};
|
|
170
204
|
FilterConsumerBridgeToSqlRequest.prototype.isIn = function (col, val) {
|
|
171
205
|
var _this = this;
|
|
206
|
+
if (val === null || val === void 0 ? void 0 : val.length)
|
|
207
|
+
this.handleNull.column(col);
|
|
172
208
|
this.promises.push((function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
173
209
|
var _this = this;
|
|
174
210
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -220,6 +256,7 @@ var FilterConsumerBridgeToSqlRequest = /** @class */ (function () {
|
|
|
220
256
|
FilterConsumerBridgeToSqlRequest.prototype.like = function (col, pattern, not) {
|
|
221
257
|
var _this = this;
|
|
222
258
|
if (not === void 0) { not = ''; }
|
|
259
|
+
this.handleNull.column(col);
|
|
223
260
|
this.promises.push((function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
224
261
|
return tslib_1.__generator(this, function (_a) {
|
|
225
262
|
this.addToWhere(not +
|
|
@@ -235,6 +272,7 @@ var FilterConsumerBridgeToSqlRequest = /** @class */ (function () {
|
|
|
235
272
|
};
|
|
236
273
|
FilterConsumerBridgeToSqlRequest.prototype.add = function (col, val, operator) {
|
|
237
274
|
var _this = this;
|
|
275
|
+
this.handleNull.column(col);
|
|
238
276
|
this.promises.push((function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
239
277
|
var x;
|
|
240
278
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -272,6 +310,7 @@ var FilterConsumerBridgeToSqlRequest = /** @class */ (function () {
|
|
|
272
310
|
if (typeof sql !== 'string')
|
|
273
311
|
sql = item.sql;
|
|
274
312
|
if (sql) {
|
|
313
|
+
this.handleNull.custom();
|
|
275
314
|
this.addToWhere('(' + sql + ')');
|
|
276
315
|
}
|
|
277
316
|
_a.label = 2;
|