remult 2.7.33 → 2.7.34
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/remult-knex/index.js +10 -5
- package/package.json +1 -1
- package/remult-knex/index.js +10 -5
package/esm/remult-knex/index.js
CHANGED
|
@@ -119,12 +119,17 @@ class KnexEntityDataProvider {
|
|
|
119
119
|
async groupBy(options) {
|
|
120
120
|
return groupByImpl(options, await dbNamesOf(this.entity, this.dp.wrapIdentifier), this.dp.createCommand(), false, (limit, offset) => ' limit ' + limit + ' offset ' + offset);
|
|
121
121
|
}
|
|
122
|
+
getEntityFrom(e) {
|
|
123
|
+
if (this.entity.options.sqlExpression)
|
|
124
|
+
return this.knex.fromRaw(e.$entityName);
|
|
125
|
+
return this.knex(e.$entityName);
|
|
126
|
+
}
|
|
122
127
|
async count(where) {
|
|
123
128
|
const e = await this.init();
|
|
124
129
|
const br = new FilterConsumerBridgeToKnexRequest(e, this.rawSqlWrapIdentifier);
|
|
125
130
|
where.__applyToConsumer(br);
|
|
126
131
|
let r = await br.resolveWhere();
|
|
127
|
-
const result = await this.
|
|
132
|
+
const result = await this.getEntityFrom(e)
|
|
128
133
|
.count()
|
|
129
134
|
.where((b) => r.forEach((w) => w(b)));
|
|
130
135
|
var row = result[0];
|
|
@@ -151,7 +156,7 @@ class KnexEntityDataProvider {
|
|
|
151
156
|
colKeys.push(x);
|
|
152
157
|
}
|
|
153
158
|
}
|
|
154
|
-
let query = this.
|
|
159
|
+
let query = this.getEntityFrom(e).select(cols);
|
|
155
160
|
if (options?.where) {
|
|
156
161
|
const br = new FilterConsumerBridgeToKnexRequest(e, this.rawSqlWrapIdentifier);
|
|
157
162
|
options.where.__applyToConsumer(br);
|
|
@@ -218,7 +223,7 @@ class KnexEntityDataProvider {
|
|
|
218
223
|
}
|
|
219
224
|
}
|
|
220
225
|
let where = await f.resolveWhere();
|
|
221
|
-
await this.
|
|
226
|
+
await this.getEntityFrom(e)
|
|
222
227
|
.update(updateObject)
|
|
223
228
|
.where((b) => where.forEach((w) => w(b)));
|
|
224
229
|
return getRowAfterUpdate(this.entity, this, data, id, 'update');
|
|
@@ -228,7 +233,7 @@ class KnexEntityDataProvider {
|
|
|
228
233
|
let f = new FilterConsumerBridgeToKnexRequest(e, this.rawSqlWrapIdentifier);
|
|
229
234
|
Filter.fromEntityFilter(this.entity, this.entity.idMetadata.getIdFilter(id)).__applyToConsumer(f);
|
|
230
235
|
let where = await f.resolveWhere();
|
|
231
|
-
await this.
|
|
236
|
+
await this.getEntityFrom(e)
|
|
232
237
|
.delete()
|
|
233
238
|
.where((b) => where.forEach((w) => w(b)));
|
|
234
239
|
}
|
|
@@ -246,7 +251,7 @@ class KnexEntityDataProvider {
|
|
|
246
251
|
}
|
|
247
252
|
}
|
|
248
253
|
}
|
|
249
|
-
let insert = this.
|
|
254
|
+
let insert = this.getEntityFrom(e).insert(insertObject);
|
|
250
255
|
if (isAutoIncrement(this.entity.idMetadata.field)) {
|
|
251
256
|
let newId;
|
|
252
257
|
if (this.knex.client.config.client === 'mysql2' ||
|
package/package.json
CHANGED
package/remult-knex/index.js
CHANGED
|
@@ -217,6 +217,11 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
217
217
|
});
|
|
218
218
|
});
|
|
219
219
|
};
|
|
220
|
+
KnexEntityDataProvider.prototype.getEntityFrom = function (e) {
|
|
221
|
+
if (this.entity.options.sqlExpression)
|
|
222
|
+
return this.knex.fromRaw(e.$entityName);
|
|
223
|
+
return this.knex(e.$entityName);
|
|
224
|
+
};
|
|
220
225
|
KnexEntityDataProvider.prototype.count = function (where) {
|
|
221
226
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
222
227
|
var e, br, r, result, row, key, element;
|
|
@@ -230,7 +235,7 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
230
235
|
return [4 /*yield*/, br.resolveWhere()];
|
|
231
236
|
case 2:
|
|
232
237
|
r = _a.sent();
|
|
233
|
-
return [4 /*yield*/, this.
|
|
238
|
+
return [4 /*yield*/, this.getEntityFrom(e)
|
|
234
239
|
.count()
|
|
235
240
|
.where(function (b) { return r.forEach(function (w) { return w(b); }); })];
|
|
236
241
|
case 3:
|
|
@@ -279,7 +284,7 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
279
284
|
}
|
|
280
285
|
finally { if (e_3) throw e_3.error; }
|
|
281
286
|
}
|
|
282
|
-
query = this.
|
|
287
|
+
query = this.getEntityFrom(e).select(cols);
|
|
283
288
|
if (!(options === null || options === void 0 ? void 0 : options.where)) return [3 /*break*/, 3];
|
|
284
289
|
br = new FilterConsumerBridgeToKnexRequest(e, this.rawSqlWrapIdentifier);
|
|
285
290
|
options.where.__applyToConsumer(br);
|
|
@@ -395,7 +400,7 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
395
400
|
case 10: return [4 /*yield*/, f.resolveWhere()];
|
|
396
401
|
case 11:
|
|
397
402
|
where = _d.sent();
|
|
398
|
-
return [4 /*yield*/, this.
|
|
403
|
+
return [4 /*yield*/, this.getEntityFrom(e)
|
|
399
404
|
.update(updateObject)
|
|
400
405
|
.where(function (b) { return where.forEach(function (w) { return w(b); }); })];
|
|
401
406
|
case 12:
|
|
@@ -418,7 +423,7 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
418
423
|
return [4 /*yield*/, f.resolveWhere()];
|
|
419
424
|
case 2:
|
|
420
425
|
where = _a.sent();
|
|
421
|
-
return [4 /*yield*/, this.
|
|
426
|
+
return [4 /*yield*/, this.getEntityFrom(e)
|
|
422
427
|
.delete()
|
|
423
428
|
.where(function (b) { return where.forEach(function (w) { return w(b); }); })];
|
|
424
429
|
case 3:
|
|
@@ -472,7 +477,7 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
472
477
|
finally { if (e_5) throw e_5.error; }
|
|
473
478
|
return [7 /*endfinally*/];
|
|
474
479
|
case 10:
|
|
475
|
-
insert = this.
|
|
480
|
+
insert = this.getEntityFrom(e).insert(insertObject);
|
|
476
481
|
if (!(0, RepositoryImplementation_js_1.isAutoIncrement)(this.entity.idMetadata.field)) return [3 /*break*/, 15];
|
|
477
482
|
if (!(this.knex.client.config.client === 'mysql2' ||
|
|
478
483
|
this.knex.client.config.client === 'mysql')) return [3 /*break*/, 12];
|