remult 0.10.13 → 0.11.3
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/package.json +1 -1
- package/postgres/postgres-data-provider.d.ts +3 -3
- package/postgres/postgres-data-provider.js +136 -190
- package/remult-knex/index.d.ts +6 -5
- package/remult-knex/index.js +251 -289
- package/remult-mongo.js +150 -217
- package/server/expressBridge.d.ts +5 -0
- package/server/expressBridge.js +17 -1
- package/src/backend-tests/backend-database-test-setup.backend-spec.d.ts +1 -1
- package/src/backend-tests/backend-database-test-setup.backend-spec.js +75 -52
- package/src/data-interfaces.d.ts +0 -2
- package/src/data-providers/sql-database.d.ts +0 -2
- package/src/data-providers/sql-database.js +199 -298
- package/src/data-providers/web-sql-data-provider.js +38 -56
- package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +15 -1
- package/src/filter/filter-consumer-bridge-to-sql-request.js +80 -50
- package/src/remult3/RepositoryImplementation.d.ts +9 -1
- package/src/remult3/RepositoryImplementation.js +50 -18
- package/src/remult3/remult3.d.ts +5 -3
- package/src/shared-tests/db-tests.db-tests.js +63 -2
- package/src/tests/entityForCustomFilter.js +24 -22
- package/valueConverters.js +1 -1
package/remult-knex/index.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.createKnexDataProvider = exports.buildColumn = exports.KnexSchemaBuilder
|
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var __1 = require("..");
|
|
6
6
|
var knex_1 = require("knex");
|
|
7
|
-
var
|
|
7
|
+
var filter_consumer_bridge_to_sql_request_1 = require("../src/filter/filter-consumer-bridge-to-sql-request");
|
|
8
8
|
var context_1 = require("../src/context");
|
|
9
9
|
var valueConverters_1 = require("../valueConverters");
|
|
10
10
|
var KnexDataProvider = /** @class */ (function () {
|
|
@@ -53,106 +53,86 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
53
53
|
}
|
|
54
54
|
KnexEntityDataProvider.prototype.count = function (where) {
|
|
55
55
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
56
|
-
var br, r,
|
|
57
|
-
return tslib_1.__generator(this, function (
|
|
58
|
-
switch (
|
|
59
|
-
case 0:
|
|
60
|
-
|
|
56
|
+
var e, br, r, result, row, key, element;
|
|
57
|
+
return tslib_1.__generator(this, function (_a) {
|
|
58
|
+
switch (_a.label) {
|
|
59
|
+
case 0: return [4 /*yield*/, this.init()];
|
|
60
|
+
case 1:
|
|
61
|
+
e = _a.sent();
|
|
62
|
+
br = new FilterConsumerBridgeToKnexRequest(e);
|
|
61
63
|
where.__applyToConsumer(br);
|
|
62
64
|
return [4 /*yield*/, br.resolveWhere()];
|
|
63
|
-
case
|
|
64
|
-
r =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
case
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
case 2:
|
|
66
|
+
r = _a.sent();
|
|
67
|
+
return [4 /*yield*/, this.knex(e.entityName)
|
|
68
|
+
.count().where(function (b) { return r.forEach(function (w) { return w(b); }); })];
|
|
69
|
+
case 3:
|
|
70
|
+
result = (_a.sent());
|
|
71
|
+
row = result[0];
|
|
72
|
+
for (key in row) {
|
|
73
|
+
if (Object.prototype.hasOwnProperty.call(row, key)) {
|
|
74
|
+
element = row[key];
|
|
75
|
+
return [2 /*return*/, +element];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return [2 /*return*/];
|
|
70
79
|
}
|
|
71
80
|
});
|
|
72
81
|
});
|
|
73
82
|
};
|
|
74
83
|
KnexEntityDataProvider.prototype.find = function (options) {
|
|
75
84
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
76
|
-
var cols, colKeys, _a, _b, x,
|
|
77
|
-
var e_1,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
case
|
|
85
|
+
var e, cols, colKeys, _a, _b, x, query, br, r_1, r;
|
|
86
|
+
var e_1, _c;
|
|
87
|
+
return tslib_1.__generator(this, function (_d) {
|
|
88
|
+
switch (_d.label) {
|
|
89
|
+
case 0: return [4 /*yield*/, this.init()];
|
|
90
|
+
case 1:
|
|
91
|
+
e = _d.sent();
|
|
82
92
|
cols = [];
|
|
83
93
|
colKeys = [];
|
|
84
|
-
_j.label = 1;
|
|
85
|
-
case 1:
|
|
86
|
-
_j.trys.push([1, 7, 8, 9]);
|
|
87
|
-
_a = tslib_1.__values(this.entity.fields), _b = _a.next();
|
|
88
|
-
_j.label = 2;
|
|
89
|
-
case 2:
|
|
90
|
-
if (!!_b.done) return [3 /*break*/, 6];
|
|
91
|
-
x = _b.value;
|
|
92
|
-
if (!x.isServerExpression) return [3 /*break*/, 3];
|
|
93
|
-
return [3 /*break*/, 5];
|
|
94
|
-
case 3:
|
|
95
|
-
_d = (_c = cols).push;
|
|
96
|
-
return [4 /*yield*/, x.getDbName()];
|
|
97
|
-
case 4:
|
|
98
|
-
_d.apply(_c, [_j.sent()]);
|
|
99
|
-
colKeys.push(x);
|
|
100
|
-
_j.label = 5;
|
|
101
|
-
case 5:
|
|
102
|
-
_b = _a.next();
|
|
103
|
-
return [3 /*break*/, 2];
|
|
104
|
-
case 6: return [3 /*break*/, 9];
|
|
105
|
-
case 7:
|
|
106
|
-
e_1_1 = _j.sent();
|
|
107
|
-
e_1 = { error: e_1_1 };
|
|
108
|
-
return [3 /*break*/, 9];
|
|
109
|
-
case 8:
|
|
110
94
|
try {
|
|
111
|
-
|
|
95
|
+
for (_a = tslib_1.__values(this.entity.fields), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
96
|
+
x = _b.value;
|
|
97
|
+
if (x.isServerExpression) {
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
cols.push(e.nameOf(x));
|
|
101
|
+
colKeys.push(x);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
112
104
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
105
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
106
|
+
finally {
|
|
107
|
+
try {
|
|
108
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
109
|
+
}
|
|
110
|
+
finally { if (e_1) throw e_1.error; }
|
|
111
|
+
}
|
|
112
|
+
query = this.knex(e.entityName).select(cols);
|
|
113
|
+
if (!(options === null || options === void 0 ? void 0 : options.where)) return [3 /*break*/, 3];
|
|
114
|
+
br = new FilterConsumerBridgeToKnexRequest(e);
|
|
122
115
|
options.where.__applyToConsumer(br);
|
|
123
116
|
return [4 /*yield*/, br.resolveWhere()];
|
|
124
|
-
case
|
|
125
|
-
r_1 =
|
|
117
|
+
case 2:
|
|
118
|
+
r_1 = _d.sent();
|
|
126
119
|
query.where(function (b) { return r_1.forEach(function (y) { return y(b); }); });
|
|
127
|
-
|
|
128
|
-
case
|
|
129
|
-
if (
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
case 0:
|
|
136
|
-
_a = {};
|
|
137
|
-
return [4 /*yield*/, s.field.getDbName()];
|
|
138
|
-
case 1: return [2 /*return*/, (_a.column = _b.sent(),
|
|
139
|
-
_a.order = s.isDescending ? "desc" : "asc",
|
|
140
|
-
_a)];
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
}); }))];
|
|
144
|
-
case 13:
|
|
145
|
-
query = _g.apply(_f, [_j.sent()]);
|
|
146
|
-
_j.label = 14;
|
|
147
|
-
case 14:
|
|
120
|
+
_d.label = 3;
|
|
121
|
+
case 3:
|
|
122
|
+
if (options.orderBy) {
|
|
123
|
+
query = query.orderBy(options.orderBy.Segments.map(function (s) { return ({
|
|
124
|
+
column: e.nameOf(s.field),
|
|
125
|
+
order: s.isDescending ? "desc" : "asc"
|
|
126
|
+
}); }));
|
|
127
|
+
}
|
|
148
128
|
if (options.limit) {
|
|
149
129
|
query = query.limit(options.limit);
|
|
150
130
|
if (options.page)
|
|
151
131
|
query = query.offset((options.page - 1) * options.limit);
|
|
152
132
|
}
|
|
153
133
|
return [4 /*yield*/, query];
|
|
154
|
-
case
|
|
155
|
-
r =
|
|
134
|
+
case 4:
|
|
135
|
+
r = _d.sent();
|
|
156
136
|
return [2 /*return*/, r.map(function (y) {
|
|
157
137
|
var result = {};
|
|
158
138
|
var i = 0;
|
|
@@ -171,62 +151,70 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
171
151
|
});
|
|
172
152
|
});
|
|
173
153
|
};
|
|
154
|
+
KnexEntityDataProvider.prototype.init = function () {
|
|
155
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
156
|
+
return tslib_1.__generator(this, function (_a) {
|
|
157
|
+
switch (_a.label) {
|
|
158
|
+
case 0: return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.getDbNameProvider(this.entity)];
|
|
159
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
};
|
|
174
164
|
KnexEntityDataProvider.prototype.update = function (id, data) {
|
|
175
165
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
176
|
-
var f, resultFilter, updateObject, _a, _b, x, v, key, e_2_1, where
|
|
177
|
-
var e_2,
|
|
178
|
-
return tslib_1.__generator(this, function (
|
|
179
|
-
switch (
|
|
180
|
-
case 0:
|
|
181
|
-
|
|
166
|
+
var e, f, resultFilter, updateObject, _a, _b, x, v, key, e_2_1, where;
|
|
167
|
+
var e_2, _c;
|
|
168
|
+
return tslib_1.__generator(this, function (_d) {
|
|
169
|
+
switch (_d.label) {
|
|
170
|
+
case 0: return [4 /*yield*/, this.init()];
|
|
171
|
+
case 1:
|
|
172
|
+
e = _d.sent();
|
|
173
|
+
f = new FilterConsumerBridgeToKnexRequest(e);
|
|
182
174
|
__1.Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
183
175
|
resultFilter = this.entity.idMetadata.getIdFilter(id);
|
|
184
176
|
if (data.id != undefined)
|
|
185
177
|
resultFilter = this.entity.idMetadata.getIdFilter(data.id);
|
|
186
178
|
updateObject = {};
|
|
187
|
-
|
|
188
|
-
case 1:
|
|
189
|
-
_e.trys.push([1, 8, 9, 10]);
|
|
190
|
-
_a = tslib_1.__values(this.entity.fields), _b = _a.next();
|
|
191
|
-
_e.label = 2;
|
|
179
|
+
_d.label = 2;
|
|
192
180
|
case 2:
|
|
181
|
+
_d.trys.push([2, 8, 9, 10]);
|
|
182
|
+
_a = tslib_1.__values(this.entity.fields), _b = _a.next();
|
|
183
|
+
_d.label = 3;
|
|
184
|
+
case 3:
|
|
193
185
|
if (!!_b.done) return [3 /*break*/, 7];
|
|
194
186
|
x = _b.value;
|
|
195
|
-
return [
|
|
196
|
-
case 3:
|
|
197
|
-
if (!_e.sent()) return [3 /*break*/, 4];
|
|
187
|
+
if (!e.isDbReadonly(x)) return [3 /*break*/, 4];
|
|
198
188
|
return [3 /*break*/, 6];
|
|
199
189
|
case 4:
|
|
200
190
|
if (!(data[x.key] !== undefined)) return [3 /*break*/, 6];
|
|
201
191
|
v = x.valueConverter.toDb(data[x.key]);
|
|
202
192
|
if (!(v !== undefined)) return [3 /*break*/, 6];
|
|
203
|
-
return [4 /*yield*/,
|
|
193
|
+
return [4 /*yield*/, e.nameOf(x)];
|
|
204
194
|
case 5:
|
|
205
|
-
key =
|
|
195
|
+
key = _d.sent();
|
|
206
196
|
updateObject[key] = v;
|
|
207
|
-
|
|
197
|
+
_d.label = 6;
|
|
208
198
|
case 6:
|
|
209
199
|
_b = _a.next();
|
|
210
|
-
return [3 /*break*/,
|
|
200
|
+
return [3 /*break*/, 3];
|
|
211
201
|
case 7: return [3 /*break*/, 10];
|
|
212
202
|
case 8:
|
|
213
|
-
e_2_1 =
|
|
203
|
+
e_2_1 = _d.sent();
|
|
214
204
|
e_2 = { error: e_2_1 };
|
|
215
205
|
return [3 /*break*/, 10];
|
|
216
206
|
case 9:
|
|
217
207
|
try {
|
|
218
|
-
if (_b && !_b.done && (
|
|
208
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
219
209
|
}
|
|
220
210
|
finally { if (e_2) throw e_2.error; }
|
|
221
211
|
return [7 /*endfinally*/];
|
|
222
212
|
case 10: return [4 /*yield*/, f.resolveWhere()];
|
|
223
213
|
case 11:
|
|
224
|
-
where =
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
case 13:
|
|
229
|
-
_e.sent();
|
|
214
|
+
where = _d.sent();
|
|
215
|
+
return [4 /*yield*/, this.knex(e.entityName).update(updateObject).where(function (b) { return where.forEach(function (w) { return w(b); }); })];
|
|
216
|
+
case 12:
|
|
217
|
+
_d.sent();
|
|
230
218
|
return [2 /*return*/, this.find({ where: __1.Filter.fromEntityFilter(this.entity, resultFilter) }).then(function (y) { return y[0]; })];
|
|
231
219
|
}
|
|
232
220
|
});
|
|
@@ -234,20 +222,20 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
234
222
|
};
|
|
235
223
|
KnexEntityDataProvider.prototype.delete = function (id) {
|
|
236
224
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
237
|
-
var f, where
|
|
238
|
-
return tslib_1.__generator(this, function (
|
|
239
|
-
switch (
|
|
240
|
-
case 0:
|
|
241
|
-
|
|
225
|
+
var e, f, where;
|
|
226
|
+
return tslib_1.__generator(this, function (_a) {
|
|
227
|
+
switch (_a.label) {
|
|
228
|
+
case 0: return [4 /*yield*/, this.init()];
|
|
229
|
+
case 1:
|
|
230
|
+
e = _a.sent();
|
|
231
|
+
f = new FilterConsumerBridgeToKnexRequest(e);
|
|
242
232
|
__1.Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
243
233
|
return [4 /*yield*/, f.resolveWhere()];
|
|
244
|
-
case
|
|
245
|
-
where =
|
|
246
|
-
|
|
247
|
-
return [4 /*yield*/, this.entity.getDbName()];
|
|
248
|
-
case 2: return [4 /*yield*/, _a.apply(this, [_b.sent()]).delete().where(function (b) { return where.forEach(function (w) { return w(b); }); })];
|
|
234
|
+
case 2:
|
|
235
|
+
where = _a.sent();
|
|
236
|
+
return [4 /*yield*/, this.knex(e.entityName).delete().where(function (b) { return where.forEach(function (w) { return w(b); }); })];
|
|
249
237
|
case 3:
|
|
250
|
-
|
|
238
|
+
_a.sent();
|
|
251
239
|
return [2 /*return*/];
|
|
252
240
|
}
|
|
253
241
|
});
|
|
@@ -255,67 +243,65 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
255
243
|
};
|
|
256
244
|
KnexEntityDataProvider.prototype.insert = function (data) {
|
|
257
245
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
258
|
-
var resultFilter, insertObject, _a, _b, x, v, key, e_3_1, insert,
|
|
259
|
-
var e_3,
|
|
246
|
+
var e, resultFilter, insertObject, _a, _b, x, v, key, e_3_1, insert, result, newId_1;
|
|
247
|
+
var e_3, _c;
|
|
260
248
|
var _this = this;
|
|
261
|
-
return tslib_1.__generator(this, function (
|
|
262
|
-
switch (
|
|
263
|
-
case 0:
|
|
249
|
+
return tslib_1.__generator(this, function (_d) {
|
|
250
|
+
switch (_d.label) {
|
|
251
|
+
case 0: return [4 /*yield*/, this.init()];
|
|
252
|
+
case 1:
|
|
253
|
+
e = _d.sent();
|
|
264
254
|
if (this.entity.idMetadata.field instanceof __1.CompoundIdField)
|
|
265
255
|
resultFilter = this.entity.idMetadata.field.resultIdFilter(undefined, data);
|
|
266
256
|
else
|
|
267
257
|
resultFilter = __1.Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(data[this.entity.idMetadata.field.key]));
|
|
268
258
|
insertObject = {};
|
|
269
|
-
|
|
270
|
-
case 1:
|
|
271
|
-
_e.trys.push([1, 8, 9, 10]);
|
|
272
|
-
_a = tslib_1.__values(this.entity.fields), _b = _a.next();
|
|
273
|
-
_e.label = 2;
|
|
259
|
+
_d.label = 2;
|
|
274
260
|
case 2:
|
|
261
|
+
_d.trys.push([2, 8, 9, 10]);
|
|
262
|
+
_a = tslib_1.__values(this.entity.fields), _b = _a.next();
|
|
263
|
+
_d.label = 3;
|
|
264
|
+
case 3:
|
|
275
265
|
if (!!_b.done) return [3 /*break*/, 7];
|
|
276
266
|
x = _b.value;
|
|
277
|
-
return [
|
|
278
|
-
case 3:
|
|
279
|
-
if (!_e.sent()) return [3 /*break*/, 4];
|
|
267
|
+
if (!e.isDbReadonly(x)) return [3 /*break*/, 4];
|
|
280
268
|
return [3 /*break*/, 6];
|
|
281
269
|
case 4:
|
|
282
270
|
v = x.valueConverter.toDb(data[x.key]);
|
|
283
271
|
if (!(v != undefined)) return [3 /*break*/, 6];
|
|
284
|
-
return [4 /*yield*/,
|
|
272
|
+
return [4 /*yield*/, e.nameOf(x)];
|
|
285
273
|
case 5:
|
|
286
|
-
key =
|
|
274
|
+
key = _d.sent();
|
|
287
275
|
insertObject[key] = v;
|
|
288
|
-
|
|
276
|
+
_d.label = 6;
|
|
289
277
|
case 6:
|
|
290
278
|
_b = _a.next();
|
|
291
|
-
return [3 /*break*/,
|
|
279
|
+
return [3 /*break*/, 3];
|
|
292
280
|
case 7: return [3 /*break*/, 10];
|
|
293
281
|
case 8:
|
|
294
|
-
e_3_1 =
|
|
282
|
+
e_3_1 = _d.sent();
|
|
295
283
|
e_3 = { error: e_3_1 };
|
|
296
284
|
return [3 /*break*/, 10];
|
|
297
285
|
case 9:
|
|
298
286
|
try {
|
|
299
|
-
if (_b && !_b.done && (
|
|
287
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
300
288
|
}
|
|
301
289
|
finally { if (e_3) throw e_3.error; }
|
|
302
290
|
return [7 /*endfinally*/];
|
|
303
291
|
case 10:
|
|
304
|
-
|
|
305
|
-
return [
|
|
306
|
-
case 11:
|
|
307
|
-
insert = _c.apply(this, [_e.sent()]).insert(insertObject);
|
|
308
|
-
if (!this.entity.options.dbAutoIncrementId) return [3 /*break*/, 13];
|
|
292
|
+
insert = this.knex(e.entityName).insert(insertObject);
|
|
293
|
+
if (!this.entity.options.dbAutoIncrementId) return [3 /*break*/, 12];
|
|
309
294
|
return [4 /*yield*/, insert.returning(this.entity.idMetadata.field.key)];
|
|
310
|
-
case
|
|
311
|
-
|
|
295
|
+
case 11:
|
|
296
|
+
result = _d.sent();
|
|
297
|
+
newId_1 = result[0].id;
|
|
312
298
|
resultFilter = new __1.Filter(function (x) { return x.isEqualTo(_this.entity.idMetadata.field, newId_1); });
|
|
313
|
-
return [3 /*break*/,
|
|
314
|
-
case
|
|
315
|
-
case
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
case
|
|
299
|
+
return [3 /*break*/, 14];
|
|
300
|
+
case 12: return [4 /*yield*/, insert];
|
|
301
|
+
case 13:
|
|
302
|
+
_d.sent();
|
|
303
|
+
_d.label = 14;
|
|
304
|
+
case 14: return [2 /*return*/, this.find({ where: resultFilter }).then(function (y) {
|
|
319
305
|
return y[0];
|
|
320
306
|
})];
|
|
321
307
|
}
|
|
@@ -325,7 +311,8 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
325
311
|
return KnexEntityDataProvider;
|
|
326
312
|
}());
|
|
327
313
|
var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
328
|
-
function FilterConsumerBridgeToKnexRequest() {
|
|
314
|
+
function FilterConsumerBridgeToKnexRequest(nameProvider) {
|
|
315
|
+
this.nameProvider = nameProvider;
|
|
329
316
|
this._addWhere = true;
|
|
330
317
|
this.promises = [];
|
|
331
318
|
this.result = [];
|
|
@@ -379,24 +366,25 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
379
366
|
var _this = this;
|
|
380
367
|
var statement = '';
|
|
381
368
|
this.promises.push((function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
382
|
-
var _loop_1, this_1, orElements_1, orElements_1_1, element, e_5_1;
|
|
369
|
+
var result, _loop_1, this_1, orElements_1, orElements_1_1, element, e_5_1;
|
|
383
370
|
var e_5, _a;
|
|
384
371
|
return tslib_1.__generator(this, function (_b) {
|
|
385
372
|
switch (_b.label) {
|
|
386
373
|
case 0:
|
|
374
|
+
result = [];
|
|
387
375
|
_loop_1 = function (element) {
|
|
388
376
|
var f, where;
|
|
389
377
|
return tslib_1.__generator(this, function (_a) {
|
|
390
378
|
switch (_a.label) {
|
|
391
379
|
case 0:
|
|
392
|
-
f = new FilterConsumerBridgeToKnexRequest();
|
|
380
|
+
f = new FilterConsumerBridgeToKnexRequest(this_1.nameProvider);
|
|
393
381
|
f._addWhere = false;
|
|
394
382
|
element.__applyToConsumer(f);
|
|
395
383
|
return [4 /*yield*/, f.resolveWhere()];
|
|
396
384
|
case 1:
|
|
397
385
|
where = _a.sent();
|
|
398
386
|
if (where.length > 0) {
|
|
399
|
-
|
|
387
|
+
result.push(function (b) {
|
|
400
388
|
b.orWhere(function (b) {
|
|
401
389
|
where.forEach(function (x) { return x(b); });
|
|
402
390
|
});
|
|
@@ -433,26 +421,28 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
433
421
|
}
|
|
434
422
|
finally { if (e_5) throw e_5.error; }
|
|
435
423
|
return [7 /*endfinally*/];
|
|
436
|
-
case 8:
|
|
424
|
+
case 8:
|
|
425
|
+
if (result.length > 0) {
|
|
426
|
+
this.result.push(function (b) { return b.where(function (x) { return result.find(function (y) { return y(x); }); }); });
|
|
427
|
+
}
|
|
428
|
+
return [2 /*return*/];
|
|
437
429
|
}
|
|
438
430
|
});
|
|
439
431
|
}); })());
|
|
440
432
|
};
|
|
441
433
|
FilterConsumerBridgeToKnexRequest.prototype.isNull = function (col) {
|
|
442
434
|
var _this = this;
|
|
443
|
-
this.
|
|
435
|
+
this.result.push(function (b) { return b.whereNull(_this.nameProvider.nameOf(col)); });
|
|
444
436
|
};
|
|
445
437
|
FilterConsumerBridgeToKnexRequest.prototype.isNotNull = function (col) {
|
|
446
438
|
var _this = this;
|
|
447
|
-
this.
|
|
439
|
+
this.result.push(function (b) { return b.whereNotNull(_this.nameProvider.nameOf(col)); });
|
|
448
440
|
};
|
|
449
441
|
FilterConsumerBridgeToKnexRequest.prototype.isIn = function (col, val) {
|
|
450
442
|
var _this = this;
|
|
451
|
-
this.
|
|
452
|
-
_this.
|
|
453
|
-
|
|
454
|
-
});
|
|
455
|
-
}));
|
|
443
|
+
this.result.push(function (knex) {
|
|
444
|
+
return knex.whereIn(_this.nameProvider.nameOf(col), val.map(function (x) { return col.valueConverter.toDb(x); }));
|
|
445
|
+
});
|
|
456
446
|
};
|
|
457
447
|
FilterConsumerBridgeToKnexRequest.prototype.isEqualTo = function (col, val) {
|
|
458
448
|
this.add(col, val, "=");
|
|
@@ -474,9 +464,7 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
474
464
|
};
|
|
475
465
|
FilterConsumerBridgeToKnexRequest.prototype.containsCaseInsensitive = function (col, val) {
|
|
476
466
|
var _this = this;
|
|
477
|
-
this.
|
|
478
|
-
_this.result.push(function (b) { return b.whereRaw('lower (' + colName + ") like lower ('%" + val.replace(/'/g, '\'\'') + "%')"); });
|
|
479
|
-
}));
|
|
467
|
+
this.result.push(function (b) { return b.whereRaw('lower (' + _this.nameProvider.nameOf(col) + ") like lower ('%" + val.replace(/'/g, '\'\'') + "%')"); });
|
|
480
468
|
this.promises.push((function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
481
469
|
return tslib_1.__generator(this, function (_a) {
|
|
482
470
|
return [2 /*return*/];
|
|
@@ -485,9 +473,7 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
485
473
|
};
|
|
486
474
|
FilterConsumerBridgeToKnexRequest.prototype.add = function (col, val, operator) {
|
|
487
475
|
var _this = this;
|
|
488
|
-
this.
|
|
489
|
-
_this.result.push(function (b) { return b.where(colName, operator, col.valueConverter.toDb(val)); });
|
|
490
|
-
}));
|
|
476
|
+
this.result.push(function (b) { return b.where(_this.nameProvider.nameOf(col), operator, col.valueConverter.toDb(val)); });
|
|
491
477
|
};
|
|
492
478
|
FilterConsumerBridgeToKnexRequest.prototype.databaseCustom = function (databaseCustom) {
|
|
493
479
|
throw "error";
|
|
@@ -544,7 +530,7 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
544
530
|
case 8:
|
|
545
531
|
err_1 = _e.sent();
|
|
546
532
|
_b = (_a = console).log;
|
|
547
|
-
_c = "failed verify
|
|
533
|
+
_c = "failed verify structure of ";
|
|
548
534
|
return [4 /*yield*/, metadata.getDbName()];
|
|
549
535
|
case 9:
|
|
550
536
|
_b.apply(_a, [_c + (_e.sent()) + " ", err_1]);
|
|
@@ -568,175 +554,151 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
568
554
|
});
|
|
569
555
|
});
|
|
570
556
|
};
|
|
571
|
-
KnexSchemaBuilder.prototype.createIfNotExist = function (
|
|
557
|
+
KnexSchemaBuilder.prototype.createIfNotExist = function (entity) {
|
|
572
558
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
573
|
-
var
|
|
574
|
-
var e_7,
|
|
575
|
-
return tslib_1.__generator(this, function (
|
|
576
|
-
switch (
|
|
577
|
-
case 0:
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
559
|
+
var e, cols_1, _a, _b, f;
|
|
560
|
+
var e_7, _c;
|
|
561
|
+
return tslib_1.__generator(this, function (_d) {
|
|
562
|
+
switch (_d.label) {
|
|
563
|
+
case 0: return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.getDbNameProvider(entity)];
|
|
564
|
+
case 1:
|
|
565
|
+
e = _d.sent();
|
|
566
|
+
return [4 /*yield*/, this.knex.schema.hasTable(e.entityName)];
|
|
581
567
|
case 2:
|
|
582
|
-
if (!!(
|
|
568
|
+
if (!!(_d.sent())) return [3 /*break*/, 4];
|
|
583
569
|
cols_1 = new Map();
|
|
584
|
-
_o.label = 3;
|
|
585
|
-
case 3:
|
|
586
|
-
_o.trys.push([3, 9, 10, 11]);
|
|
587
|
-
_c = tslib_1.__values(e.fields), _d = _c.next();
|
|
588
|
-
_o.label = 4;
|
|
589
|
-
case 4:
|
|
590
|
-
if (!!_d.done) return [3 /*break*/, 8];
|
|
591
|
-
f = _d.value;
|
|
592
|
-
_f = (_e = cols_1).set;
|
|
593
|
-
_g = [f];
|
|
594
|
-
_m = {};
|
|
595
|
-
return [4 /*yield*/, f.getDbName()];
|
|
596
|
-
case 5:
|
|
597
|
-
_m.name = _o.sent();
|
|
598
|
-
return [4 /*yield*/, sql_database_1.isDbReadonly(f)];
|
|
599
|
-
case 6:
|
|
600
|
-
_f.apply(_e, _g.concat([(_m.readonly = _o.sent(),
|
|
601
|
-
_m)]));
|
|
602
|
-
_o.label = 7;
|
|
603
|
-
case 7:
|
|
604
|
-
_d = _c.next();
|
|
605
|
-
return [3 /*break*/, 4];
|
|
606
|
-
case 8: return [3 /*break*/, 11];
|
|
607
|
-
case 9:
|
|
608
|
-
e_7_1 = _o.sent();
|
|
609
|
-
e_7 = { error: e_7_1 };
|
|
610
|
-
return [3 /*break*/, 11];
|
|
611
|
-
case 10:
|
|
612
570
|
try {
|
|
613
|
-
|
|
571
|
+
for (_a = tslib_1.__values(entity.fields), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
572
|
+
f = _b.value;
|
|
573
|
+
cols_1.set(f, {
|
|
574
|
+
name: e.nameOf(f),
|
|
575
|
+
readonly: e.isDbReadonly(f)
|
|
576
|
+
});
|
|
577
|
+
}
|
|
614
578
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
}
|
|
579
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
580
|
+
finally {
|
|
581
|
+
try {
|
|
582
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
583
|
+
}
|
|
584
|
+
finally { if (e_7) throw e_7.error; }
|
|
585
|
+
}
|
|
586
|
+
return [4 /*yield*/, logSql(this.knex.schema.createTable(e.entityName, function (b) {
|
|
587
|
+
var e_8, _a;
|
|
588
|
+
try {
|
|
589
|
+
for (var _b = tslib_1.__values(entity.fields), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
590
|
+
var x = _c.value;
|
|
591
|
+
if (!cols_1.get(x).readonly || x == entity.idMetadata.field && entity.options.dbAutoIncrementId) {
|
|
592
|
+
if (x == entity.idMetadata.field && entity.options.dbAutoIncrementId)
|
|
593
|
+
b.increments(cols_1.get(x).name);
|
|
594
|
+
else {
|
|
595
|
+
buildColumn(x, cols_1.get(x).name, b);
|
|
596
|
+
if (x == entity.idMetadata.field)
|
|
597
|
+
b.primary([cols_1.get(x).name]);
|
|
635
598
|
}
|
|
636
599
|
}
|
|
637
600
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
finally { if (e_8) throw e_8.error; }
|
|
601
|
+
}
|
|
602
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
603
|
+
finally {
|
|
604
|
+
try {
|
|
605
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
644
606
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
607
|
+
finally { if (e_8) throw e_8.error; }
|
|
608
|
+
}
|
|
609
|
+
}))];
|
|
610
|
+
case 3:
|
|
611
|
+
_d.sent();
|
|
612
|
+
_d.label = 4;
|
|
613
|
+
case 4: return [2 /*return*/];
|
|
650
614
|
}
|
|
651
615
|
});
|
|
652
616
|
});
|
|
653
617
|
};
|
|
654
|
-
KnexSchemaBuilder.prototype.addColumnIfNotExist = function (
|
|
618
|
+
KnexSchemaBuilder.prototype.addColumnIfNotExist = function (entity, c) {
|
|
655
619
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
656
|
-
var col, colName
|
|
657
|
-
return tslib_1.__generator(this, function (
|
|
658
|
-
switch (
|
|
659
|
-
case 0: return [4 /*yield*/,
|
|
620
|
+
var e, col, colName;
|
|
621
|
+
return tslib_1.__generator(this, function (_a) {
|
|
622
|
+
switch (_a.label) {
|
|
623
|
+
case 0: return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.getDbNameProvider(entity)];
|
|
660
624
|
case 1:
|
|
661
|
-
|
|
625
|
+
e = _a.sent();
|
|
626
|
+
if (e.isDbReadonly(c(entity)))
|
|
662
627
|
return [2 /*return*/];
|
|
663
|
-
col = c(
|
|
664
|
-
|
|
628
|
+
col = c(entity);
|
|
629
|
+
colName = e.nameOf(col);
|
|
630
|
+
return [4 /*yield*/, this.knex.schema.hasColumn(e.entityName, colName)];
|
|
665
631
|
case 2:
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
return [4 /*yield*/, e.getDbName()];
|
|
669
|
-
case 3: return [4 /*yield*/, _b.apply(_a, [_e.sent(), colName])];
|
|
670
|
-
case 4:
|
|
671
|
-
if (!!(_e.sent())) return [3 /*break*/, 7];
|
|
672
|
-
_d = (_c = this.knex.schema).alterTable;
|
|
673
|
-
return [4 /*yield*/, e.getDbName()];
|
|
674
|
-
case 5: return [4 /*yield*/, _d.apply(_c, [_e.sent(), function (b) {
|
|
632
|
+
if (!!(_a.sent())) return [3 /*break*/, 4];
|
|
633
|
+
return [4 /*yield*/, this.knex.schema.alterTable(e.entityName, function (b) {
|
|
675
634
|
buildColumn(col, colName, b);
|
|
676
|
-
}
|
|
677
|
-
case
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
case
|
|
635
|
+
})];
|
|
636
|
+
case 3:
|
|
637
|
+
_a.sent();
|
|
638
|
+
_a.label = 4;
|
|
639
|
+
case 4: return [2 /*return*/];
|
|
681
640
|
}
|
|
682
641
|
});
|
|
683
642
|
});
|
|
684
643
|
};
|
|
685
|
-
KnexSchemaBuilder.prototype.verifyAllColumns = function (
|
|
644
|
+
KnexSchemaBuilder.prototype.verifyAllColumns = function (entity) {
|
|
686
645
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
687
|
-
var _loop_2, this_2, _a, _b, col, e_9_1, err_2;
|
|
646
|
+
var e, _loop_2, this_2, _a, _b, col, e_9_1, err_2;
|
|
688
647
|
var e_9, _c;
|
|
689
648
|
return tslib_1.__generator(this, function (_d) {
|
|
690
649
|
switch (_d.label) {
|
|
691
|
-
case 0:
|
|
692
|
-
|
|
650
|
+
case 0: return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.getDbNameProvider(entity)];
|
|
651
|
+
case 1:
|
|
652
|
+
e = _d.sent();
|
|
653
|
+
_d.label = 2;
|
|
654
|
+
case 2:
|
|
655
|
+
_d.trys.push([2, 11, , 12]);
|
|
693
656
|
_loop_2 = function (col) {
|
|
694
657
|
return tslib_1.__generator(this, function (_a) {
|
|
695
658
|
switch (_a.label) {
|
|
696
|
-
case 0:
|
|
659
|
+
case 0:
|
|
660
|
+
if (!!e.isDbReadonly(col)) return [3 /*break*/, 2];
|
|
661
|
+
return [4 /*yield*/, this_2.addColumnIfNotExist(entity, function () { return col; })];
|
|
697
662
|
case 1:
|
|
698
|
-
if (!!(_a.sent())) return [3 /*break*/, 3];
|
|
699
|
-
return [4 /*yield*/, this_2.addColumnIfNotExist(e, function () { return col; })];
|
|
700
|
-
case 2:
|
|
701
663
|
_a.sent();
|
|
702
|
-
_a.label =
|
|
703
|
-
case
|
|
664
|
+
_a.label = 2;
|
|
665
|
+
case 2: return [2 /*return*/];
|
|
704
666
|
}
|
|
705
667
|
});
|
|
706
668
|
};
|
|
707
669
|
this_2 = this;
|
|
708
|
-
_d.label =
|
|
709
|
-
case 1:
|
|
710
|
-
_d.trys.push([1, 6, 7, 8]);
|
|
711
|
-
_a = tslib_1.__values(e.fields), _b = _a.next();
|
|
712
|
-
_d.label = 2;
|
|
713
|
-
case 2:
|
|
714
|
-
if (!!_b.done) return [3 /*break*/, 5];
|
|
715
|
-
col = _b.value;
|
|
716
|
-
return [5 /*yield**/, _loop_2(col)];
|
|
670
|
+
_d.label = 3;
|
|
717
671
|
case 3:
|
|
718
|
-
_d.
|
|
672
|
+
_d.trys.push([3, 8, 9, 10]);
|
|
673
|
+
_a = tslib_1.__values(entity.fields), _b = _a.next();
|
|
719
674
|
_d.label = 4;
|
|
720
675
|
case 4:
|
|
721
|
-
_b
|
|
722
|
-
|
|
723
|
-
|
|
676
|
+
if (!!_b.done) return [3 /*break*/, 7];
|
|
677
|
+
col = _b.value;
|
|
678
|
+
return [5 /*yield**/, _loop_2(col)];
|
|
679
|
+
case 5:
|
|
680
|
+
_d.sent();
|
|
681
|
+
_d.label = 6;
|
|
724
682
|
case 6:
|
|
683
|
+
_b = _a.next();
|
|
684
|
+
return [3 /*break*/, 4];
|
|
685
|
+
case 7: return [3 /*break*/, 10];
|
|
686
|
+
case 8:
|
|
725
687
|
e_9_1 = _d.sent();
|
|
726
688
|
e_9 = { error: e_9_1 };
|
|
727
|
-
return [3 /*break*/,
|
|
728
|
-
case
|
|
689
|
+
return [3 /*break*/, 10];
|
|
690
|
+
case 9:
|
|
729
691
|
try {
|
|
730
692
|
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
731
693
|
}
|
|
732
694
|
finally { if (e_9) throw e_9.error; }
|
|
733
695
|
return [7 /*endfinally*/];
|
|
734
|
-
case
|
|
735
|
-
case
|
|
696
|
+
case 10: return [3 /*break*/, 12];
|
|
697
|
+
case 11:
|
|
736
698
|
err_2 = _d.sent();
|
|
737
699
|
console.log(err_2);
|
|
738
|
-
return [3 /*break*/,
|
|
739
|
-
case
|
|
700
|
+
return [3 /*break*/, 12];
|
|
701
|
+
case 12: return [2 /*return*/];
|
|
740
702
|
}
|
|
741
703
|
});
|
|
742
704
|
});
|