@spinajs/orm 1.0.56 → 1.2.26
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/README.md +11 -2
- package/lib/builders.d.ts +30 -23
- package/lib/builders.js +71 -200
- package/lib/builders.js.map +1 -1
- package/lib/decorators.d.ts +18 -19
- package/lib/decorators.js +21 -21
- package/lib/decorators.js.map +1 -1
- package/lib/driver.d.ts +8 -9
- package/lib/driver.js +5 -20
- package/lib/driver.js.map +1 -1
- package/lib/exceptions.d.ts +6 -0
- package/lib/exceptions.js +11 -0
- package/lib/exceptions.js.map +1 -0
- package/lib/helpers.js +2 -2
- package/lib/helpers.js.map +1 -1
- package/lib/hydrators.d.ts +4 -4
- package/lib/hydrators.js +6 -6
- package/lib/hydrators.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +1 -2
- package/lib/index.js.map +1 -1
- package/lib/interfaces.d.ts +19 -27
- package/lib/interfaces.js +14 -14
- package/lib/interfaces.js.map +1 -1
- package/lib/model.d.ts +55 -53
- package/lib/model.js +132 -149
- package/lib/model.js.map +1 -1
- package/lib/orm.d.ts +9 -9
- package/lib/orm.js +66 -40
- package/lib/orm.js.map +1 -1
- package/lib/relations.d.ts +14 -13
- package/lib/relations.js +60 -81
- package/lib/relations.js.map +1 -1
- package/lib/statements.d.ts +1 -1
- package/lib/statements.js +19 -21
- package/lib/statements.js.map +1 -1
- package/lib/wrappers.d.ts +1 -1
- package/lib/wrappers.js.map +1 -1
- package/package.json +37 -61
- package/LICENSE +0 -674
package/lib/builders.js
CHANGED
|
@@ -1,29 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
2
|
+
/* eslint-disable prettier/prettier */
|
|
14
3
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
15
4
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
5
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
6
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
7
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
8
|
};
|
|
20
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
-
if (mod && mod.__esModule) return mod;
|
|
22
|
-
var result = {};
|
|
23
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
-
__setModuleDefault(result, mod);
|
|
25
|
-
return result;
|
|
26
|
-
};
|
|
27
9
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
28
10
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
29
11
|
};
|
|
@@ -32,7 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
14
|
exports.SchemaQueryBuilder = exports.TableQueryBuilder = exports.ColumnQueryBuilder = exports.ForeignKeyBuilder = exports.IndexQueryBuilder = exports.InsertQueryBuilder = exports.UpdateQueryBuilder = exports.OnDuplicateQueryBuilder = exports.DeleteQueryBuilder = exports.SelectQueryBuilder = exports.WhereBuilder = exports.WithRecursiveBuilder = exports.JoinBuilder = exports.GroupByBuilder = exports.RawQuery = exports.ColumnsBuilder = exports.OrderByBuilder = exports.LimitBuilder = exports.QueryBuilder = exports.Builder = void 0;
|
|
33
15
|
const di_1 = require("@spinajs/di");
|
|
34
16
|
const exceptions_1 = require("@spinajs/exceptions");
|
|
35
|
-
const _ =
|
|
17
|
+
const _ = require("lodash");
|
|
36
18
|
const typescript_mix_1 = require("typescript-mix");
|
|
37
19
|
const enums_1 = require("./enums");
|
|
38
20
|
const interfaces_1 = require("./interfaces");
|
|
@@ -78,7 +60,7 @@ let Builder = class Builder {
|
|
|
78
60
|
return current.afterData(result);
|
|
79
61
|
}, []);
|
|
80
62
|
}
|
|
81
|
-
const models = transformedResult.map(r => {
|
|
63
|
+
const models = transformedResult.map((r) => {
|
|
82
64
|
let model = null;
|
|
83
65
|
for (const middleware of this._middlewares) {
|
|
84
66
|
model = middleware.modelCreation(r);
|
|
@@ -115,8 +97,8 @@ let Builder = class Builder {
|
|
|
115
97
|
}
|
|
116
98
|
};
|
|
117
99
|
Builder = __decorate([
|
|
118
|
-
di_1.NewInstance(),
|
|
119
|
-
di_1.Inject(di_1.Container),
|
|
100
|
+
(0, di_1.NewInstance)(),
|
|
101
|
+
(0, di_1.Inject)(di_1.Container),
|
|
120
102
|
__metadata("design:paramtypes", [di_1.Container, driver_1.OrmDriver, Object])
|
|
121
103
|
], Builder);
|
|
122
104
|
exports.Builder = Builder;
|
|
@@ -186,7 +168,7 @@ let QueryBuilder = class QueryBuilder extends Builder {
|
|
|
186
168
|
/**
|
|
187
169
|
* Sets table alias for query
|
|
188
170
|
*
|
|
189
|
-
* @param alias sql table alias
|
|
171
|
+
* @param alias - sql table alias
|
|
190
172
|
*/
|
|
191
173
|
setAlias(alias) {
|
|
192
174
|
this._tableAlias = alias;
|
|
@@ -197,8 +179,8 @@ let QueryBuilder = class QueryBuilder extends Builder {
|
|
|
197
179
|
}
|
|
198
180
|
};
|
|
199
181
|
QueryBuilder = __decorate([
|
|
200
|
-
di_1.NewInstance(),
|
|
201
|
-
di_1.Inject(di_1.Container),
|
|
182
|
+
(0, di_1.NewInstance)(),
|
|
183
|
+
(0, di_1.Inject)(di_1.Container),
|
|
202
184
|
__metadata("design:paramtypes", [di_1.Container, driver_1.OrmDriver, Object])
|
|
203
185
|
], QueryBuilder);
|
|
204
186
|
exports.QueryBuilder = QueryBuilder;
|
|
@@ -239,7 +221,7 @@ let LimitBuilder = class LimitBuilder {
|
|
|
239
221
|
}
|
|
240
222
|
};
|
|
241
223
|
LimitBuilder = __decorate([
|
|
242
|
-
di_1.NewInstance(),
|
|
224
|
+
(0, di_1.NewInstance)(),
|
|
243
225
|
__metadata("design:paramtypes", [])
|
|
244
226
|
], LimitBuilder);
|
|
245
227
|
exports.LimitBuilder = LimitBuilder;
|
|
@@ -276,7 +258,7 @@ let OrderByBuilder = class OrderByBuilder {
|
|
|
276
258
|
}
|
|
277
259
|
};
|
|
278
260
|
OrderByBuilder = __decorate([
|
|
279
|
-
di_1.NewInstance(),
|
|
261
|
+
(0, di_1.NewInstance)(),
|
|
280
262
|
__metadata("design:paramtypes", [])
|
|
281
263
|
], OrderByBuilder);
|
|
282
264
|
exports.OrderByBuilder = OrderByBuilder;
|
|
@@ -297,39 +279,24 @@ let ColumnsBuilder = class ColumnsBuilder {
|
|
|
297
279
|
return this;
|
|
298
280
|
}
|
|
299
281
|
columns(names) {
|
|
300
|
-
const descriptor = model_1.extractModelDescriptor(this._model);
|
|
301
|
-
this._columns = names.map(n => {
|
|
302
|
-
return this._container.resolve(statements_1.ColumnStatement, [
|
|
303
|
-
n,
|
|
304
|
-
null,
|
|
305
|
-
this._tableAlias,
|
|
306
|
-
descriptor === null || descriptor === void 0 ? void 0 : descriptor.Columns.find(c => c.Name === n),
|
|
307
|
-
]);
|
|
282
|
+
const descriptor = (0, model_1.extractModelDescriptor)(this._model);
|
|
283
|
+
this._columns = names.map((n) => {
|
|
284
|
+
return this._container.resolve(statements_1.ColumnStatement, [n, null, this._tableAlias, descriptor === null || descriptor === void 0 ? void 0 : descriptor.Columns.find((c) => c.Name === n)]);
|
|
308
285
|
});
|
|
309
286
|
return this;
|
|
310
287
|
}
|
|
311
288
|
select(column, alias) {
|
|
312
|
-
const descriptor = model_1.extractModelDescriptor(this._model);
|
|
289
|
+
const descriptor = (0, model_1.extractModelDescriptor)(this._model);
|
|
313
290
|
if (column instanceof Map) {
|
|
314
291
|
column.forEach((alias, colName) => {
|
|
315
|
-
this._columns.push(this._container.resolve(statements_1.ColumnStatement, [
|
|
316
|
-
colName,
|
|
317
|
-
alias,
|
|
318
|
-
this._tableAlias,
|
|
319
|
-
descriptor === null || descriptor === void 0 ? void 0 : descriptor.Columns.find(c => c.Name === colName),
|
|
320
|
-
]));
|
|
292
|
+
this._columns.push(this._container.resolve(statements_1.ColumnStatement, [colName, alias, this._tableAlias, descriptor === null || descriptor === void 0 ? void 0 : descriptor.Columns.find((c) => c.Name === colName)]));
|
|
321
293
|
});
|
|
322
294
|
}
|
|
323
295
|
if (column instanceof RawQuery) {
|
|
324
296
|
this._columns.push(this._container.resolve(statements_1.ColumnRawStatement, [column, null, this._tableAlias]));
|
|
325
297
|
}
|
|
326
298
|
else {
|
|
327
|
-
this._columns.push(this._container.resolve(statements_1.ColumnStatement, [
|
|
328
|
-
column,
|
|
329
|
-
alias,
|
|
330
|
-
this._tableAlias,
|
|
331
|
-
descriptor === null || descriptor === void 0 ? void 0 : descriptor.Columns.find(c => c.Name === column),
|
|
332
|
-
]));
|
|
299
|
+
this._columns.push(this._container.resolve(statements_1.ColumnStatement, [column, alias, this._tableAlias, descriptor === null || descriptor === void 0 ? void 0 : descriptor.Columns.find((c) => c.Name === column)]));
|
|
333
300
|
}
|
|
334
301
|
return this;
|
|
335
302
|
}
|
|
@@ -338,7 +305,7 @@ let ColumnsBuilder = class ColumnsBuilder {
|
|
|
338
305
|
}
|
|
339
306
|
};
|
|
340
307
|
ColumnsBuilder = __decorate([
|
|
341
|
-
di_1.NewInstance(),
|
|
308
|
+
(0, di_1.NewInstance)(),
|
|
342
309
|
__metadata("design:paramtypes", [])
|
|
343
310
|
], ColumnsBuilder);
|
|
344
311
|
exports.ColumnsBuilder = ColumnsBuilder;
|
|
@@ -360,7 +327,7 @@ let RawQuery = RawQuery_1 = class RawQuery {
|
|
|
360
327
|
}
|
|
361
328
|
};
|
|
362
329
|
RawQuery = RawQuery_1 = __decorate([
|
|
363
|
-
di_1.NewInstance(),
|
|
330
|
+
(0, di_1.NewInstance)(),
|
|
364
331
|
__metadata("design:paramtypes", [String, Array])
|
|
365
332
|
], RawQuery);
|
|
366
333
|
exports.RawQuery = RawQuery;
|
|
@@ -425,24 +392,10 @@ class JoinBuilder {
|
|
|
425
392
|
addJoinStatement(method, table, AliasOrForeignKey, fkOrPkKey, primaryKey) {
|
|
426
393
|
let stmt = null;
|
|
427
394
|
if (arguments.length === 4) {
|
|
428
|
-
stmt = this._container.resolve(statements_1.JoinStatement, [
|
|
429
|
-
table,
|
|
430
|
-
method,
|
|
431
|
-
AliasOrForeignKey,
|
|
432
|
-
fkOrPkKey,
|
|
433
|
-
null,
|
|
434
|
-
this._tableAlias,
|
|
435
|
-
]);
|
|
395
|
+
stmt = this._container.resolve(statements_1.JoinStatement, [table, method, AliasOrForeignKey, fkOrPkKey, null, this._tableAlias]);
|
|
436
396
|
}
|
|
437
397
|
else if (arguments.length === 5) {
|
|
438
|
-
stmt = this._container.resolve(statements_1.JoinStatement, [
|
|
439
|
-
table,
|
|
440
|
-
method,
|
|
441
|
-
fkOrPkKey,
|
|
442
|
-
primaryKey,
|
|
443
|
-
AliasOrForeignKey,
|
|
444
|
-
this._tableAlias,
|
|
445
|
-
]);
|
|
398
|
+
stmt = this._container.resolve(statements_1.JoinStatement, [table, method, fkOrPkKey, primaryKey, AliasOrForeignKey, this._tableAlias]);
|
|
446
399
|
}
|
|
447
400
|
else {
|
|
448
401
|
stmt = this._container.resolve(statements_1.JoinStatement, [table, method]);
|
|
@@ -456,17 +409,12 @@ let WithRecursiveBuilder = class WithRecursiveBuilder {
|
|
|
456
409
|
return this._cteStatement;
|
|
457
410
|
}
|
|
458
411
|
withRecursive(rcKeyName, pkName) {
|
|
459
|
-
this._cteStatement = this._container.resolve(statements_1.WithRecursiveStatement, [
|
|
460
|
-
'cte',
|
|
461
|
-
this,
|
|
462
|
-
rcKeyName,
|
|
463
|
-
pkName,
|
|
464
|
-
]);
|
|
412
|
+
this._cteStatement = this._container.resolve(statements_1.WithRecursiveStatement, ['cte', this, rcKeyName, pkName]);
|
|
465
413
|
return this;
|
|
466
414
|
}
|
|
467
415
|
};
|
|
468
416
|
WithRecursiveBuilder = __decorate([
|
|
469
|
-
di_1.NewInstance()
|
|
417
|
+
(0, di_1.NewInstance)()
|
|
470
418
|
], WithRecursiveBuilder);
|
|
471
419
|
exports.WithRecursiveBuilder = WithRecursiveBuilder;
|
|
472
420
|
let WhereBuilder = WhereBuilder_1 = class WhereBuilder {
|
|
@@ -491,11 +439,7 @@ let WhereBuilder = WhereBuilder_1 = class WhereBuilder {
|
|
|
491
439
|
return this.where(RawQuery.create(column ? 'TRUE' : 'FALSE'));
|
|
492
440
|
}
|
|
493
441
|
if (column instanceof RawQuery) {
|
|
494
|
-
this.Statements.push(this._container.resolve(statements_1.RawQueryStatement, [
|
|
495
|
-
column.Query,
|
|
496
|
-
column.Bindings,
|
|
497
|
-
self._tableAlias,
|
|
498
|
-
]));
|
|
442
|
+
this.Statements.push(this._container.resolve(statements_1.RawQueryStatement, [column.Query, column.Bindings, self._tableAlias]));
|
|
499
443
|
return this;
|
|
500
444
|
}
|
|
501
445
|
// handle nested where's
|
|
@@ -516,18 +460,13 @@ let WhereBuilder = WhereBuilder_1 = class WhereBuilder {
|
|
|
516
460
|
/**
|
|
517
461
|
* handles for where("foo", 1).where(...) cases
|
|
518
462
|
* it produces WHERE foo = 1
|
|
519
|
-
* @param c
|
|
520
|
-
* @param operator
|
|
521
463
|
*/
|
|
522
464
|
function _handleForTwo(c, v) {
|
|
523
465
|
if (v === undefined) {
|
|
524
466
|
throw new exceptions_1.InvalidArgument(`value cannot be undefined`);
|
|
525
467
|
}
|
|
526
468
|
if (!_.isString(c) && !(c instanceof statements_1.Wrap)) {
|
|
527
|
-
throw new exceptions_1.InvalidArgument(`column is not of type string.`);
|
|
528
|
-
}
|
|
529
|
-
if (!(c instanceof statements_1.Wrap)) {
|
|
530
|
-
throw new exceptions_1.InvalidArgument(`column is not wrapped.`);
|
|
469
|
+
throw new exceptions_1.InvalidArgument(`column is not of type string or wrapped.`);
|
|
531
470
|
}
|
|
532
471
|
if (v === null) {
|
|
533
472
|
return this.whereNull(c);
|
|
@@ -538,19 +477,16 @@ let WhereBuilder = WhereBuilder_1 = class WhereBuilder {
|
|
|
538
477
|
/**
|
|
539
478
|
* Handles for where("foo",'!=',1) etc
|
|
540
479
|
* it produces WHERE foo != 1
|
|
541
|
-
* @param c
|
|
542
|
-
* @param o
|
|
543
|
-
* @param v
|
|
544
480
|
*/
|
|
545
481
|
function _handleForThree(c, o, v) {
|
|
546
482
|
if (!isWhereOperator(o)) {
|
|
547
483
|
throw new exceptions_1.InvalidArgument(`operator ${o} is invalid`);
|
|
548
484
|
}
|
|
549
485
|
if (!_.isString(c) && !(c instanceof statements_1.Wrap)) {
|
|
550
|
-
throw new exceptions_1.InvalidArgument(`column is not of type string.`);
|
|
486
|
+
throw new exceptions_1.InvalidArgument(`column is not of type string or wrapped.`);
|
|
551
487
|
}
|
|
552
|
-
if (
|
|
553
|
-
|
|
488
|
+
if (v === null) {
|
|
489
|
+
return this.whereNull(c);
|
|
554
490
|
}
|
|
555
491
|
if (v === null) {
|
|
556
492
|
return o === enums_1.WhereOperators.NOT_NULL ? this.whereNotNull(c) : this.whereNull(c);
|
|
@@ -574,12 +510,7 @@ let WhereBuilder = WhereBuilder_1 = class WhereBuilder {
|
|
|
574
510
|
return this;
|
|
575
511
|
}
|
|
576
512
|
whereNotNull(column) {
|
|
577
|
-
this._statements.push(this._container.resolve(statements_1.WhereStatement, [
|
|
578
|
-
column,
|
|
579
|
-
enums_1.WhereOperators.NOT_NULL,
|
|
580
|
-
null,
|
|
581
|
-
this._tableAlias,
|
|
582
|
-
]));
|
|
513
|
+
this._statements.push(this._container.resolve(statements_1.WhereStatement, [column, enums_1.WhereOperators.NOT_NULL, null, this._tableAlias]));
|
|
583
514
|
return this;
|
|
584
515
|
}
|
|
585
516
|
whereNull(column) {
|
|
@@ -627,7 +558,7 @@ let WhereBuilder = WhereBuilder_1 = class WhereBuilder {
|
|
|
627
558
|
}
|
|
628
559
|
};
|
|
629
560
|
WhereBuilder = WhereBuilder_1 = __decorate([
|
|
630
|
-
di_1.NewInstance(),
|
|
561
|
+
(0, di_1.NewInstance)(),
|
|
631
562
|
__metadata("design:paramtypes", [di_1.Container, String])
|
|
632
563
|
], WhereBuilder);
|
|
633
564
|
exports.WhereBuilder = WhereBuilder;
|
|
@@ -673,9 +604,9 @@ class SelectQueryBuilder extends QueryBuilder {
|
|
|
673
604
|
}
|
|
674
605
|
setAlias(alias) {
|
|
675
606
|
this._tableAlias = alias;
|
|
676
|
-
this._columns.forEach(c => (c.TableAlias = alias));
|
|
677
|
-
this._joinStatements.forEach(c => (c.TableAlias = alias));
|
|
678
|
-
this._statements.forEach(c => (c.TableAlias = alias));
|
|
607
|
+
this._columns.forEach((c) => (c.TableAlias = alias));
|
|
608
|
+
this._joinStatements.forEach((c) => (c.TableAlias = alias));
|
|
609
|
+
this._statements.forEach((c) => (c.TableAlias = alias));
|
|
679
610
|
return this;
|
|
680
611
|
}
|
|
681
612
|
clone() {
|
|
@@ -694,18 +625,13 @@ class SelectQueryBuilder extends QueryBuilder {
|
|
|
694
625
|
populate(relation, callback) {
|
|
695
626
|
var _a;
|
|
696
627
|
let relInstance = null;
|
|
697
|
-
const descriptor = model_1.extractModelDescriptor(this._model);
|
|
628
|
+
const descriptor = (0, model_1.extractModelDescriptor)(this._model);
|
|
698
629
|
if (!descriptor.Relations.has(relation)) {
|
|
699
630
|
throw new exceptions_1.InvalidArgument(`Relation ${relation} not exists in model ${(_a = this._model) === null || _a === void 0 ? void 0 : _a.constructor.name}`);
|
|
700
631
|
}
|
|
701
632
|
const relDescription = descriptor.Relations.get(relation);
|
|
702
633
|
if (relDescription.Type === interfaces_1.RelationType.One && relDescription.Recursive) {
|
|
703
|
-
relInstance = this._container.resolve(relations_1.BelongsToRecursiveRelation, [
|
|
704
|
-
this._container.get(orm_1.Orm),
|
|
705
|
-
this,
|
|
706
|
-
relDescription,
|
|
707
|
-
this._owner,
|
|
708
|
-
]);
|
|
634
|
+
relInstance = this._container.resolve(relations_1.BelongsToRecursiveRelation, [this._container.get(orm_1.Orm), this, relDescription, this._owner]);
|
|
709
635
|
}
|
|
710
636
|
else {
|
|
711
637
|
if (relDescription.Recursive) {
|
|
@@ -713,28 +639,13 @@ class SelectQueryBuilder extends QueryBuilder {
|
|
|
713
639
|
}
|
|
714
640
|
switch (relDescription.Type) {
|
|
715
641
|
case interfaces_1.RelationType.One:
|
|
716
|
-
relInstance = this._container.resolve(relations_1.BelongsToRelation, [
|
|
717
|
-
this._container.get(orm_1.Orm),
|
|
718
|
-
this,
|
|
719
|
-
relDescription,
|
|
720
|
-
this._owner,
|
|
721
|
-
]);
|
|
642
|
+
relInstance = this._container.resolve(relations_1.BelongsToRelation, [this._container.get(orm_1.Orm), this, relDescription, this._owner]);
|
|
722
643
|
break;
|
|
723
644
|
case interfaces_1.RelationType.Many:
|
|
724
|
-
relInstance = this._container.resolve(relations_1.OneToManyRelation, [
|
|
725
|
-
this._container.get(orm_1.Orm),
|
|
726
|
-
this,
|
|
727
|
-
relDescription,
|
|
728
|
-
this._owner,
|
|
729
|
-
]);
|
|
645
|
+
relInstance = this._container.resolve(relations_1.OneToManyRelation, [this._container.get(orm_1.Orm), this, relDescription, this._owner]);
|
|
730
646
|
break;
|
|
731
647
|
case interfaces_1.RelationType.ManyToMany:
|
|
732
|
-
relInstance = this._container.resolve(relations_1.ManyToManyRelation, [
|
|
733
|
-
this._container.get(orm_1.Orm),
|
|
734
|
-
this,
|
|
735
|
-
relDescription,
|
|
736
|
-
null,
|
|
737
|
-
]);
|
|
648
|
+
relInstance = this._container.resolve(relations_1.ManyToManyRelation, [this._container.get(orm_1.Orm), this, relDescription, null]);
|
|
738
649
|
break;
|
|
739
650
|
}
|
|
740
651
|
}
|
|
@@ -750,48 +661,23 @@ class SelectQueryBuilder extends QueryBuilder {
|
|
|
750
661
|
this._middlewares = this._middlewares.concat(builder._middlewares);
|
|
751
662
|
}
|
|
752
663
|
min(column, as) {
|
|
753
|
-
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [
|
|
754
|
-
column,
|
|
755
|
-
enums_1.ColumnMethods.MIN,
|
|
756
|
-
as,
|
|
757
|
-
this._tableAlias,
|
|
758
|
-
]));
|
|
664
|
+
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [column, enums_1.ColumnMethods.MIN, as, this._tableAlias]));
|
|
759
665
|
return this;
|
|
760
666
|
}
|
|
761
667
|
max(column, as) {
|
|
762
|
-
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [
|
|
763
|
-
column,
|
|
764
|
-
enums_1.ColumnMethods.MAX,
|
|
765
|
-
as,
|
|
766
|
-
this._tableAlias,
|
|
767
|
-
]));
|
|
668
|
+
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [column, enums_1.ColumnMethods.MAX, as, this._tableAlias]));
|
|
768
669
|
return this;
|
|
769
670
|
}
|
|
770
671
|
count(column, as) {
|
|
771
|
-
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [
|
|
772
|
-
column,
|
|
773
|
-
enums_1.ColumnMethods.COUNT,
|
|
774
|
-
as,
|
|
775
|
-
this._tableAlias,
|
|
776
|
-
]));
|
|
672
|
+
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [column, enums_1.ColumnMethods.COUNT, as, this._tableAlias]));
|
|
777
673
|
return this;
|
|
778
674
|
}
|
|
779
675
|
sum(column, as) {
|
|
780
|
-
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [
|
|
781
|
-
column,
|
|
782
|
-
enums_1.ColumnMethods.SUM,
|
|
783
|
-
as,
|
|
784
|
-
this._tableAlias,
|
|
785
|
-
]));
|
|
676
|
+
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [column, enums_1.ColumnMethods.SUM, as, this._tableAlias]));
|
|
786
677
|
return this;
|
|
787
678
|
}
|
|
788
679
|
avg(column, as) {
|
|
789
|
-
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [
|
|
790
|
-
column,
|
|
791
|
-
enums_1.ColumnMethods.AVG,
|
|
792
|
-
as,
|
|
793
|
-
this._tableAlias,
|
|
794
|
-
]));
|
|
680
|
+
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [column, enums_1.ColumnMethods.AVG, as, this._tableAlias]));
|
|
795
681
|
return this;
|
|
796
682
|
}
|
|
797
683
|
distinct() {
|
|
@@ -825,7 +711,7 @@ class SelectQueryBuilder extends QueryBuilder {
|
|
|
825
711
|
}
|
|
826
712
|
}
|
|
827
713
|
__decorate([
|
|
828
|
-
typescript_mix_1.use(WhereBuilder, LimitBuilder, OrderByBuilder, ColumnsBuilder, JoinBuilder, WithRecursiveBuilder, GroupByBuilder),
|
|
714
|
+
(0, typescript_mix_1.use)(WhereBuilder, LimitBuilder, OrderByBuilder, ColumnsBuilder, JoinBuilder, WithRecursiveBuilder, GroupByBuilder),
|
|
829
715
|
__metadata("design:type", Object)
|
|
830
716
|
], SelectQueryBuilder.prototype, "this", void 0);
|
|
831
717
|
exports.SelectQueryBuilder = SelectQueryBuilder;
|
|
@@ -846,9 +732,7 @@ class DeleteQueryBuilder extends QueryBuilder {
|
|
|
846
732
|
return this._truncate;
|
|
847
733
|
}
|
|
848
734
|
toDB() {
|
|
849
|
-
return this._container
|
|
850
|
-
.resolve(interfaces_1.DeleteQueryCompiler, [this])
|
|
851
|
-
.compile();
|
|
735
|
+
return this._container.resolve(interfaces_1.DeleteQueryCompiler, [this]).compile();
|
|
852
736
|
}
|
|
853
737
|
truncate() {
|
|
854
738
|
this._truncate = true;
|
|
@@ -856,7 +740,7 @@ class DeleteQueryBuilder extends QueryBuilder {
|
|
|
856
740
|
}
|
|
857
741
|
}
|
|
858
742
|
__decorate([
|
|
859
|
-
typescript_mix_1.use(WhereBuilder, LimitBuilder),
|
|
743
|
+
(0, typescript_mix_1.use)(WhereBuilder, LimitBuilder),
|
|
860
744
|
__metadata("design:type", Object)
|
|
861
745
|
], DeleteQueryBuilder.prototype, "this", void 0);
|
|
862
746
|
exports.DeleteQueryBuilder = DeleteQueryBuilder;
|
|
@@ -908,13 +792,11 @@ class UpdateQueryBuilder extends QueryBuilder {
|
|
|
908
792
|
return this;
|
|
909
793
|
}
|
|
910
794
|
toDB() {
|
|
911
|
-
return this._container
|
|
912
|
-
.resolve(interfaces_1.UpdateQueryCompiler, [this])
|
|
913
|
-
.compile();
|
|
795
|
+
return this._container.resolve(interfaces_1.UpdateQueryCompiler, [this]).compile();
|
|
914
796
|
}
|
|
915
797
|
}
|
|
916
798
|
__decorate([
|
|
917
|
-
typescript_mix_1.use(WhereBuilder),
|
|
799
|
+
(0, typescript_mix_1.use)(WhereBuilder),
|
|
918
800
|
__metadata("design:type", Object)
|
|
919
801
|
], UpdateQueryBuilder.prototype, "this", void 0);
|
|
920
802
|
exports.UpdateQueryBuilder = UpdateQueryBuilder;
|
|
@@ -942,11 +824,7 @@ class InsertQueryBuilder extends QueryBuilder {
|
|
|
942
824
|
values(data) {
|
|
943
825
|
const self = this;
|
|
944
826
|
if (Array.isArray(data)) {
|
|
945
|
-
this.columns(_.chain(data)
|
|
946
|
-
.map(_.keys)
|
|
947
|
-
.flatten()
|
|
948
|
-
.uniq()
|
|
949
|
-
.value());
|
|
827
|
+
this.columns(_.chain(data).map(_.keys).flatten().uniq().value());
|
|
950
828
|
data.forEach((d) => {
|
|
951
829
|
_addData(d);
|
|
952
830
|
});
|
|
@@ -958,8 +836,8 @@ class InsertQueryBuilder extends QueryBuilder {
|
|
|
958
836
|
function _addData(d) {
|
|
959
837
|
const binding = [];
|
|
960
838
|
self._columns
|
|
961
|
-
.filter(c => !(c.Column instanceof RawQuery))
|
|
962
|
-
.map(c => {
|
|
839
|
+
.filter((c) => !(c.Column instanceof RawQuery))
|
|
840
|
+
.map((c) => {
|
|
963
841
|
return c.Column;
|
|
964
842
|
})
|
|
965
843
|
.forEach((c) => {
|
|
@@ -975,20 +853,20 @@ class InsertQueryBuilder extends QueryBuilder {
|
|
|
975
853
|
}
|
|
976
854
|
onDuplicate(column) {
|
|
977
855
|
let columnToCheck = column;
|
|
978
|
-
if (!columnToCheck) {
|
|
979
|
-
columnToCheck = model_1.extractModelDescriptor(this._model)
|
|
856
|
+
if (!columnToCheck && this.this._model) {
|
|
857
|
+
columnToCheck = (0, model_1.extractModelDescriptor)(this._model)
|
|
858
|
+
.Columns.filter((c) => c.Unique && !c.PrimaryKey)
|
|
859
|
+
.map((c) => c.Name);
|
|
980
860
|
}
|
|
981
861
|
this.DuplicateQueryBuilder = new OnDuplicateQueryBuilder(this._container, this, columnToCheck);
|
|
982
862
|
return this.DuplicateQueryBuilder;
|
|
983
863
|
}
|
|
984
864
|
toDB() {
|
|
985
|
-
return this._container
|
|
986
|
-
.resolve(interfaces_1.InsertQueryCompiler, [this])
|
|
987
|
-
.compile();
|
|
865
|
+
return this._container.resolve(interfaces_1.InsertQueryCompiler, [this]).compile();
|
|
988
866
|
}
|
|
989
867
|
}
|
|
990
868
|
__decorate([
|
|
991
|
-
typescript_mix_1.use(ColumnsBuilder),
|
|
869
|
+
(0, typescript_mix_1.use)(ColumnsBuilder),
|
|
992
870
|
__metadata("design:type", Object)
|
|
993
871
|
], InsertQueryBuilder.prototype, "this", void 0);
|
|
994
872
|
exports.InsertQueryBuilder = InsertQueryBuilder;
|
|
@@ -1014,14 +892,12 @@ let IndexQueryBuilder = class IndexQueryBuilder extends Builder {
|
|
|
1014
892
|
return this;
|
|
1015
893
|
}
|
|
1016
894
|
toDB() {
|
|
1017
|
-
return this._container
|
|
1018
|
-
.resolve(interfaces_1.IndexQueryCompiler, [this])
|
|
1019
|
-
.compile();
|
|
895
|
+
return this._container.resolve(interfaces_1.IndexQueryCompiler, [this]).compile();
|
|
1020
896
|
}
|
|
1021
897
|
};
|
|
1022
898
|
IndexQueryBuilder = __decorate([
|
|
1023
|
-
di_1.NewInstance(),
|
|
1024
|
-
di_1.Inject(di_1.Container),
|
|
899
|
+
(0, di_1.NewInstance)(),
|
|
900
|
+
(0, di_1.Inject)(di_1.Container),
|
|
1025
901
|
__metadata("design:paramtypes", [di_1.Container, driver_1.OrmDriver])
|
|
1026
902
|
], IndexQueryBuilder);
|
|
1027
903
|
exports.IndexQueryBuilder = IndexQueryBuilder;
|
|
@@ -1034,7 +910,7 @@ let ForeignKeyBuilder = class ForeignKeyBuilder {
|
|
|
1034
910
|
*
|
|
1035
911
|
* Referenced field in child table
|
|
1036
912
|
*
|
|
1037
|
-
* @param fkName name of foreign field in child table
|
|
913
|
+
* @param fkName - name of foreign field in child table
|
|
1038
914
|
*/
|
|
1039
915
|
foreignKey(fkName) {
|
|
1040
916
|
this.ForeignKeyField = fkName;
|
|
@@ -1044,8 +920,8 @@ let ForeignKeyBuilder = class ForeignKeyBuilder {
|
|
|
1044
920
|
*
|
|
1045
921
|
* Referenced parent table & key
|
|
1046
922
|
*
|
|
1047
|
-
* @param table parent table
|
|
1048
|
-
* @param pKey parant table key field
|
|
923
|
+
* @param table - parent table
|
|
924
|
+
* @param pKey - parant table key field
|
|
1049
925
|
*/
|
|
1050
926
|
references(table, pKey) {
|
|
1051
927
|
this.Table = table;
|
|
@@ -1056,7 +932,7 @@ let ForeignKeyBuilder = class ForeignKeyBuilder {
|
|
|
1056
932
|
*
|
|
1057
933
|
* On delete action
|
|
1058
934
|
*
|
|
1059
|
-
* @param action action to take on delete
|
|
935
|
+
* @param action - action to take on delete
|
|
1060
936
|
*/
|
|
1061
937
|
onDelete(action) {
|
|
1062
938
|
this.OnDeleteAction = action;
|
|
@@ -1066,7 +942,7 @@ let ForeignKeyBuilder = class ForeignKeyBuilder {
|
|
|
1066
942
|
*
|
|
1067
943
|
* On update action
|
|
1068
944
|
*
|
|
1069
|
-
* @param action action to take on update
|
|
945
|
+
* @param action - action to take on update
|
|
1070
946
|
*/
|
|
1071
947
|
onUpdate(action) {
|
|
1072
948
|
this.OnUpdateAction = action;
|
|
@@ -1082,7 +958,7 @@ let ForeignKeyBuilder = class ForeignKeyBuilder {
|
|
|
1082
958
|
}
|
|
1083
959
|
};
|
|
1084
960
|
ForeignKeyBuilder = __decorate([
|
|
1085
|
-
di_1.NewInstance(),
|
|
961
|
+
(0, di_1.NewInstance)(),
|
|
1086
962
|
__metadata("design:paramtypes", [])
|
|
1087
963
|
], ForeignKeyBuilder);
|
|
1088
964
|
exports.ForeignKeyBuilder = ForeignKeyBuilder;
|
|
@@ -1139,7 +1015,7 @@ let ColumnQueryBuilder = class ColumnQueryBuilder {
|
|
|
1139
1015
|
}
|
|
1140
1016
|
};
|
|
1141
1017
|
ColumnQueryBuilder = __decorate([
|
|
1142
|
-
di_1.NewInstance(),
|
|
1018
|
+
(0, di_1.NewInstance)(),
|
|
1143
1019
|
__metadata("design:paramtypes", [String, String, Object])
|
|
1144
1020
|
], ColumnQueryBuilder);
|
|
1145
1021
|
exports.ColumnQueryBuilder = ColumnQueryBuilder;
|
|
@@ -1160,10 +1036,7 @@ class TableQueryBuilder extends QueryBuilder {
|
|
|
1160
1036
|
return this._foreignKeys;
|
|
1161
1037
|
}
|
|
1162
1038
|
increments(name) {
|
|
1163
|
-
return this.int(name)
|
|
1164
|
-
.autoIncrement()
|
|
1165
|
-
.notNull()
|
|
1166
|
-
.primaryKey();
|
|
1039
|
+
return this.int(name).autoIncrement().notNull().primaryKey();
|
|
1167
1040
|
}
|
|
1168
1041
|
comment(comment) {
|
|
1169
1042
|
this._comment = comment;
|
|
@@ -1178,9 +1051,7 @@ class TableQueryBuilder extends QueryBuilder {
|
|
|
1178
1051
|
return builder;
|
|
1179
1052
|
}
|
|
1180
1053
|
toDB() {
|
|
1181
|
-
return this._container
|
|
1182
|
-
.resolve(interfaces_1.TableQueryCompiler, [this])
|
|
1183
|
-
.compile();
|
|
1054
|
+
return this._container.resolve(interfaces_1.TableQueryCompiler, [this]).compile();
|
|
1184
1055
|
}
|
|
1185
1056
|
}
|
|
1186
1057
|
exports.TableQueryBuilder = TableQueryBuilder;
|
|
@@ -1196,12 +1067,12 @@ let SchemaQueryBuilder = class SchemaQueryBuilder {
|
|
|
1196
1067
|
}
|
|
1197
1068
|
};
|
|
1198
1069
|
SchemaQueryBuilder = __decorate([
|
|
1199
|
-
di_1.NewInstance(),
|
|
1200
|
-
di_1.Inject(di_1.Container),
|
|
1070
|
+
(0, di_1.NewInstance)(),
|
|
1071
|
+
(0, di_1.Inject)(di_1.Container),
|
|
1201
1072
|
__metadata("design:paramtypes", [di_1.Container, driver_1.OrmDriver])
|
|
1202
1073
|
], SchemaQueryBuilder);
|
|
1203
1074
|
exports.SchemaQueryBuilder = SchemaQueryBuilder;
|
|
1204
|
-
Object.values(enums_1.ColumnType).forEach(type => {
|
|
1075
|
+
Object.values(enums_1.ColumnType).forEach((type) => {
|
|
1205
1076
|
TableQueryBuilder.prototype[type] = function (name, ...args) {
|
|
1206
1077
|
const _builder = new ColumnQueryBuilder(name, type, ...args);
|
|
1207
1078
|
this._columns.push(_builder);
|