remult 0.11.1 → 0.11.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/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 +243 -286
- package/remult-mongo.js +150 -217
- package/server/expressBridge.js +1 -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-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/shared-tests/db-tests.db-tests.js +2 -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 = [];
|
|
@@ -389,7 +376,7 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
389
376
|
return tslib_1.__generator(this, function (_a) {
|
|
390
377
|
switch (_a.label) {
|
|
391
378
|
case 0:
|
|
392
|
-
f = new FilterConsumerBridgeToKnexRequest();
|
|
379
|
+
f = new FilterConsumerBridgeToKnexRequest(this_1.nameProvider);
|
|
393
380
|
f._addWhere = false;
|
|
394
381
|
element.__applyToConsumer(f);
|
|
395
382
|
return [4 /*yield*/, f.resolveWhere()];
|
|
@@ -440,19 +427,17 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
440
427
|
};
|
|
441
428
|
FilterConsumerBridgeToKnexRequest.prototype.isNull = function (col) {
|
|
442
429
|
var _this = this;
|
|
443
|
-
this.
|
|
430
|
+
this.result.push(function (b) { return b.whereNull(_this.nameProvider.nameOf(col)); });
|
|
444
431
|
};
|
|
445
432
|
FilterConsumerBridgeToKnexRequest.prototype.isNotNull = function (col) {
|
|
446
433
|
var _this = this;
|
|
447
|
-
this.
|
|
434
|
+
this.result.push(function (b) { return b.whereNotNull(_this.nameProvider.nameOf(col)); });
|
|
448
435
|
};
|
|
449
436
|
FilterConsumerBridgeToKnexRequest.prototype.isIn = function (col, val) {
|
|
450
437
|
var _this = this;
|
|
451
|
-
this.
|
|
452
|
-
_this.
|
|
453
|
-
|
|
454
|
-
});
|
|
455
|
-
}));
|
|
438
|
+
this.result.push(function (knex) {
|
|
439
|
+
return knex.whereIn(_this.nameProvider.nameOf(col), val.map(function (x) { return col.valueConverter.toDb(x); }));
|
|
440
|
+
});
|
|
456
441
|
};
|
|
457
442
|
FilterConsumerBridgeToKnexRequest.prototype.isEqualTo = function (col, val) {
|
|
458
443
|
this.add(col, val, "=");
|
|
@@ -474,9 +459,7 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
474
459
|
};
|
|
475
460
|
FilterConsumerBridgeToKnexRequest.prototype.containsCaseInsensitive = function (col, val) {
|
|
476
461
|
var _this = this;
|
|
477
|
-
this.
|
|
478
|
-
_this.result.push(function (b) { return b.whereRaw('lower (' + colName + ") like lower ('%" + val.replace(/'/g, '\'\'') + "%')"); });
|
|
479
|
-
}));
|
|
462
|
+
this.result.push(function (b) { return b.whereRaw('lower (' + _this.nameProvider.nameOf(col) + ") like lower ('%" + val.replace(/'/g, '\'\'') + "%')"); });
|
|
480
463
|
this.promises.push((function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
481
464
|
return tslib_1.__generator(this, function (_a) {
|
|
482
465
|
return [2 /*return*/];
|
|
@@ -485,9 +468,7 @@ var FilterConsumerBridgeToKnexRequest = /** @class */ (function () {
|
|
|
485
468
|
};
|
|
486
469
|
FilterConsumerBridgeToKnexRequest.prototype.add = function (col, val, operator) {
|
|
487
470
|
var _this = this;
|
|
488
|
-
this.
|
|
489
|
-
_this.result.push(function (b) { return b.where(colName, operator, col.valueConverter.toDb(val)); });
|
|
490
|
-
}));
|
|
471
|
+
this.result.push(function (b) { return b.where(_this.nameProvider.nameOf(col), operator, col.valueConverter.toDb(val)); });
|
|
491
472
|
};
|
|
492
473
|
FilterConsumerBridgeToKnexRequest.prototype.databaseCustom = function (databaseCustom) {
|
|
493
474
|
throw "error";
|
|
@@ -544,7 +525,7 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
544
525
|
case 8:
|
|
545
526
|
err_1 = _e.sent();
|
|
546
527
|
_b = (_a = console).log;
|
|
547
|
-
_c = "failed verify
|
|
528
|
+
_c = "failed verify structure of ";
|
|
548
529
|
return [4 /*yield*/, metadata.getDbName()];
|
|
549
530
|
case 9:
|
|
550
531
|
_b.apply(_a, [_c + (_e.sent()) + " ", err_1]);
|
|
@@ -568,175 +549,151 @@ var KnexSchemaBuilder = /** @class */ (function () {
|
|
|
568
549
|
});
|
|
569
550
|
});
|
|
570
551
|
};
|
|
571
|
-
KnexSchemaBuilder.prototype.createIfNotExist = function (
|
|
552
|
+
KnexSchemaBuilder.prototype.createIfNotExist = function (entity) {
|
|
572
553
|
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
|
-
|
|
554
|
+
var e, cols_1, _a, _b, f;
|
|
555
|
+
var e_7, _c;
|
|
556
|
+
return tslib_1.__generator(this, function (_d) {
|
|
557
|
+
switch (_d.label) {
|
|
558
|
+
case 0: return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.getDbNameProvider(entity)];
|
|
559
|
+
case 1:
|
|
560
|
+
e = _d.sent();
|
|
561
|
+
return [4 /*yield*/, this.knex.schema.hasTable(e.entityName)];
|
|
581
562
|
case 2:
|
|
582
|
-
if (!!(
|
|
563
|
+
if (!!(_d.sent())) return [3 /*break*/, 4];
|
|
583
564
|
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
565
|
try {
|
|
613
|
-
|
|
566
|
+
for (_a = tslib_1.__values(entity.fields), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
567
|
+
f = _b.value;
|
|
568
|
+
cols_1.set(f, {
|
|
569
|
+
name: e.nameOf(f),
|
|
570
|
+
readonly: e.isDbReadonly(f)
|
|
571
|
+
});
|
|
572
|
+
}
|
|
614
573
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
}
|
|
574
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
575
|
+
finally {
|
|
576
|
+
try {
|
|
577
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
578
|
+
}
|
|
579
|
+
finally { if (e_7) throw e_7.error; }
|
|
580
|
+
}
|
|
581
|
+
return [4 /*yield*/, logSql(this.knex.schema.createTable(e.entityName, function (b) {
|
|
582
|
+
var e_8, _a;
|
|
583
|
+
try {
|
|
584
|
+
for (var _b = tslib_1.__values(entity.fields), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
585
|
+
var x = _c.value;
|
|
586
|
+
if (!cols_1.get(x).readonly || x == entity.idMetadata.field && entity.options.dbAutoIncrementId) {
|
|
587
|
+
if (x == entity.idMetadata.field && entity.options.dbAutoIncrementId)
|
|
588
|
+
b.increments(cols_1.get(x).name);
|
|
589
|
+
else {
|
|
590
|
+
buildColumn(x, cols_1.get(x).name, b);
|
|
591
|
+
if (x == entity.idMetadata.field)
|
|
592
|
+
b.primary([cols_1.get(x).name]);
|
|
635
593
|
}
|
|
636
594
|
}
|
|
637
595
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
finally { if (e_8) throw e_8.error; }
|
|
596
|
+
}
|
|
597
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
598
|
+
finally {
|
|
599
|
+
try {
|
|
600
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
644
601
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
602
|
+
finally { if (e_8) throw e_8.error; }
|
|
603
|
+
}
|
|
604
|
+
}))];
|
|
605
|
+
case 3:
|
|
606
|
+
_d.sent();
|
|
607
|
+
_d.label = 4;
|
|
608
|
+
case 4: return [2 /*return*/];
|
|
650
609
|
}
|
|
651
610
|
});
|
|
652
611
|
});
|
|
653
612
|
};
|
|
654
|
-
KnexSchemaBuilder.prototype.addColumnIfNotExist = function (
|
|
613
|
+
KnexSchemaBuilder.prototype.addColumnIfNotExist = function (entity, c) {
|
|
655
614
|
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*/,
|
|
615
|
+
var e, col, colName;
|
|
616
|
+
return tslib_1.__generator(this, function (_a) {
|
|
617
|
+
switch (_a.label) {
|
|
618
|
+
case 0: return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.getDbNameProvider(entity)];
|
|
660
619
|
case 1:
|
|
661
|
-
|
|
620
|
+
e = _a.sent();
|
|
621
|
+
if (e.isDbReadonly(c(entity)))
|
|
662
622
|
return [2 /*return*/];
|
|
663
|
-
col = c(
|
|
664
|
-
|
|
623
|
+
col = c(entity);
|
|
624
|
+
colName = e.nameOf(col);
|
|
625
|
+
return [4 /*yield*/, this.knex.schema.hasColumn(e.entityName, colName)];
|
|
665
626
|
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) {
|
|
627
|
+
if (!!(_a.sent())) return [3 /*break*/, 4];
|
|
628
|
+
return [4 /*yield*/, this.knex.schema.alterTable(e.entityName, function (b) {
|
|
675
629
|
buildColumn(col, colName, b);
|
|
676
|
-
}
|
|
677
|
-
case
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
case
|
|
630
|
+
})];
|
|
631
|
+
case 3:
|
|
632
|
+
_a.sent();
|
|
633
|
+
_a.label = 4;
|
|
634
|
+
case 4: return [2 /*return*/];
|
|
681
635
|
}
|
|
682
636
|
});
|
|
683
637
|
});
|
|
684
638
|
};
|
|
685
|
-
KnexSchemaBuilder.prototype.verifyAllColumns = function (
|
|
639
|
+
KnexSchemaBuilder.prototype.verifyAllColumns = function (entity) {
|
|
686
640
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
687
|
-
var _loop_2, this_2, _a, _b, col, e_9_1, err_2;
|
|
641
|
+
var e, _loop_2, this_2, _a, _b, col, e_9_1, err_2;
|
|
688
642
|
var e_9, _c;
|
|
689
643
|
return tslib_1.__generator(this, function (_d) {
|
|
690
644
|
switch (_d.label) {
|
|
691
|
-
case 0:
|
|
692
|
-
|
|
645
|
+
case 0: return [4 /*yield*/, filter_consumer_bridge_to_sql_request_1.getDbNameProvider(entity)];
|
|
646
|
+
case 1:
|
|
647
|
+
e = _d.sent();
|
|
648
|
+
_d.label = 2;
|
|
649
|
+
case 2:
|
|
650
|
+
_d.trys.push([2, 11, , 12]);
|
|
693
651
|
_loop_2 = function (col) {
|
|
694
652
|
return tslib_1.__generator(this, function (_a) {
|
|
695
653
|
switch (_a.label) {
|
|
696
|
-
case 0:
|
|
654
|
+
case 0:
|
|
655
|
+
if (!!e.isDbReadonly(col)) return [3 /*break*/, 2];
|
|
656
|
+
return [4 /*yield*/, this_2.addColumnIfNotExist(entity, function () { return col; })];
|
|
697
657
|
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
658
|
_a.sent();
|
|
702
|
-
_a.label =
|
|
703
|
-
case
|
|
659
|
+
_a.label = 2;
|
|
660
|
+
case 2: return [2 /*return*/];
|
|
704
661
|
}
|
|
705
662
|
});
|
|
706
663
|
};
|
|
707
664
|
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)];
|
|
665
|
+
_d.label = 3;
|
|
717
666
|
case 3:
|
|
718
|
-
_d.
|
|
667
|
+
_d.trys.push([3, 8, 9, 10]);
|
|
668
|
+
_a = tslib_1.__values(entity.fields), _b = _a.next();
|
|
719
669
|
_d.label = 4;
|
|
720
670
|
case 4:
|
|
721
|
-
_b
|
|
722
|
-
|
|
723
|
-
|
|
671
|
+
if (!!_b.done) return [3 /*break*/, 7];
|
|
672
|
+
col = _b.value;
|
|
673
|
+
return [5 /*yield**/, _loop_2(col)];
|
|
674
|
+
case 5:
|
|
675
|
+
_d.sent();
|
|
676
|
+
_d.label = 6;
|
|
724
677
|
case 6:
|
|
678
|
+
_b = _a.next();
|
|
679
|
+
return [3 /*break*/, 4];
|
|
680
|
+
case 7: return [3 /*break*/, 10];
|
|
681
|
+
case 8:
|
|
725
682
|
e_9_1 = _d.sent();
|
|
726
683
|
e_9 = { error: e_9_1 };
|
|
727
|
-
return [3 /*break*/,
|
|
728
|
-
case
|
|
684
|
+
return [3 /*break*/, 10];
|
|
685
|
+
case 9:
|
|
729
686
|
try {
|
|
730
687
|
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
731
688
|
}
|
|
732
689
|
finally { if (e_9) throw e_9.error; }
|
|
733
690
|
return [7 /*endfinally*/];
|
|
734
|
-
case
|
|
735
|
-
case
|
|
691
|
+
case 10: return [3 /*break*/, 12];
|
|
692
|
+
case 11:
|
|
736
693
|
err_2 = _d.sent();
|
|
737
694
|
console.log(err_2);
|
|
738
|
-
return [3 /*break*/,
|
|
739
|
-
case
|
|
695
|
+
return [3 /*break*/, 12];
|
|
696
|
+
case 12: return [2 /*return*/];
|
|
740
697
|
}
|
|
741
698
|
});
|
|
742
699
|
});
|