@spinajs/orm 1.0.60 → 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 +67 -193
- 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,8 +460,6 @@ 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) {
|
|
@@ -535,9 +477,6 @@ let WhereBuilder = WhereBuilder_1 = class WhereBuilder {
|
|
|
535
477
|
/**
|
|
536
478
|
* Handles for where("foo",'!=',1) etc
|
|
537
479
|
* it produces WHERE foo != 1
|
|
538
|
-
* @param c
|
|
539
|
-
* @param o
|
|
540
|
-
* @param v
|
|
541
480
|
*/
|
|
542
481
|
function _handleForThree(c, o, v) {
|
|
543
482
|
if (!isWhereOperator(o)) {
|
|
@@ -571,12 +510,7 @@ let WhereBuilder = WhereBuilder_1 = class WhereBuilder {
|
|
|
571
510
|
return this;
|
|
572
511
|
}
|
|
573
512
|
whereNotNull(column) {
|
|
574
|
-
this._statements.push(this._container.resolve(statements_1.WhereStatement, [
|
|
575
|
-
column,
|
|
576
|
-
enums_1.WhereOperators.NOT_NULL,
|
|
577
|
-
null,
|
|
578
|
-
this._tableAlias,
|
|
579
|
-
]));
|
|
513
|
+
this._statements.push(this._container.resolve(statements_1.WhereStatement, [column, enums_1.WhereOperators.NOT_NULL, null, this._tableAlias]));
|
|
580
514
|
return this;
|
|
581
515
|
}
|
|
582
516
|
whereNull(column) {
|
|
@@ -624,7 +558,7 @@ let WhereBuilder = WhereBuilder_1 = class WhereBuilder {
|
|
|
624
558
|
}
|
|
625
559
|
};
|
|
626
560
|
WhereBuilder = WhereBuilder_1 = __decorate([
|
|
627
|
-
di_1.NewInstance(),
|
|
561
|
+
(0, di_1.NewInstance)(),
|
|
628
562
|
__metadata("design:paramtypes", [di_1.Container, String])
|
|
629
563
|
], WhereBuilder);
|
|
630
564
|
exports.WhereBuilder = WhereBuilder;
|
|
@@ -670,9 +604,9 @@ class SelectQueryBuilder extends QueryBuilder {
|
|
|
670
604
|
}
|
|
671
605
|
setAlias(alias) {
|
|
672
606
|
this._tableAlias = alias;
|
|
673
|
-
this._columns.forEach(c => (c.TableAlias = alias));
|
|
674
|
-
this._joinStatements.forEach(c => (c.TableAlias = alias));
|
|
675
|
-
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));
|
|
676
610
|
return this;
|
|
677
611
|
}
|
|
678
612
|
clone() {
|
|
@@ -691,18 +625,13 @@ class SelectQueryBuilder extends QueryBuilder {
|
|
|
691
625
|
populate(relation, callback) {
|
|
692
626
|
var _a;
|
|
693
627
|
let relInstance = null;
|
|
694
|
-
const descriptor = model_1.extractModelDescriptor(this._model);
|
|
628
|
+
const descriptor = (0, model_1.extractModelDescriptor)(this._model);
|
|
695
629
|
if (!descriptor.Relations.has(relation)) {
|
|
696
630
|
throw new exceptions_1.InvalidArgument(`Relation ${relation} not exists in model ${(_a = this._model) === null || _a === void 0 ? void 0 : _a.constructor.name}`);
|
|
697
631
|
}
|
|
698
632
|
const relDescription = descriptor.Relations.get(relation);
|
|
699
633
|
if (relDescription.Type === interfaces_1.RelationType.One && relDescription.Recursive) {
|
|
700
|
-
relInstance = this._container.resolve(relations_1.BelongsToRecursiveRelation, [
|
|
701
|
-
this._container.get(orm_1.Orm),
|
|
702
|
-
this,
|
|
703
|
-
relDescription,
|
|
704
|
-
this._owner,
|
|
705
|
-
]);
|
|
634
|
+
relInstance = this._container.resolve(relations_1.BelongsToRecursiveRelation, [this._container.get(orm_1.Orm), this, relDescription, this._owner]);
|
|
706
635
|
}
|
|
707
636
|
else {
|
|
708
637
|
if (relDescription.Recursive) {
|
|
@@ -710,28 +639,13 @@ class SelectQueryBuilder extends QueryBuilder {
|
|
|
710
639
|
}
|
|
711
640
|
switch (relDescription.Type) {
|
|
712
641
|
case interfaces_1.RelationType.One:
|
|
713
|
-
relInstance = this._container.resolve(relations_1.BelongsToRelation, [
|
|
714
|
-
this._container.get(orm_1.Orm),
|
|
715
|
-
this,
|
|
716
|
-
relDescription,
|
|
717
|
-
this._owner,
|
|
718
|
-
]);
|
|
642
|
+
relInstance = this._container.resolve(relations_1.BelongsToRelation, [this._container.get(orm_1.Orm), this, relDescription, this._owner]);
|
|
719
643
|
break;
|
|
720
644
|
case interfaces_1.RelationType.Many:
|
|
721
|
-
relInstance = this._container.resolve(relations_1.OneToManyRelation, [
|
|
722
|
-
this._container.get(orm_1.Orm),
|
|
723
|
-
this,
|
|
724
|
-
relDescription,
|
|
725
|
-
this._owner,
|
|
726
|
-
]);
|
|
645
|
+
relInstance = this._container.resolve(relations_1.OneToManyRelation, [this._container.get(orm_1.Orm), this, relDescription, this._owner]);
|
|
727
646
|
break;
|
|
728
647
|
case interfaces_1.RelationType.ManyToMany:
|
|
729
|
-
relInstance = this._container.resolve(relations_1.ManyToManyRelation, [
|
|
730
|
-
this._container.get(orm_1.Orm),
|
|
731
|
-
this,
|
|
732
|
-
relDescription,
|
|
733
|
-
null,
|
|
734
|
-
]);
|
|
648
|
+
relInstance = this._container.resolve(relations_1.ManyToManyRelation, [this._container.get(orm_1.Orm), this, relDescription, null]);
|
|
735
649
|
break;
|
|
736
650
|
}
|
|
737
651
|
}
|
|
@@ -747,48 +661,23 @@ class SelectQueryBuilder extends QueryBuilder {
|
|
|
747
661
|
this._middlewares = this._middlewares.concat(builder._middlewares);
|
|
748
662
|
}
|
|
749
663
|
min(column, as) {
|
|
750
|
-
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [
|
|
751
|
-
column,
|
|
752
|
-
enums_1.ColumnMethods.MIN,
|
|
753
|
-
as,
|
|
754
|
-
this._tableAlias,
|
|
755
|
-
]));
|
|
664
|
+
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [column, enums_1.ColumnMethods.MIN, as, this._tableAlias]));
|
|
756
665
|
return this;
|
|
757
666
|
}
|
|
758
667
|
max(column, as) {
|
|
759
|
-
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [
|
|
760
|
-
column,
|
|
761
|
-
enums_1.ColumnMethods.MAX,
|
|
762
|
-
as,
|
|
763
|
-
this._tableAlias,
|
|
764
|
-
]));
|
|
668
|
+
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [column, enums_1.ColumnMethods.MAX, as, this._tableAlias]));
|
|
765
669
|
return this;
|
|
766
670
|
}
|
|
767
671
|
count(column, as) {
|
|
768
|
-
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [
|
|
769
|
-
column,
|
|
770
|
-
enums_1.ColumnMethods.COUNT,
|
|
771
|
-
as,
|
|
772
|
-
this._tableAlias,
|
|
773
|
-
]));
|
|
672
|
+
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [column, enums_1.ColumnMethods.COUNT, as, this._tableAlias]));
|
|
774
673
|
return this;
|
|
775
674
|
}
|
|
776
675
|
sum(column, as) {
|
|
777
|
-
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [
|
|
778
|
-
column,
|
|
779
|
-
enums_1.ColumnMethods.SUM,
|
|
780
|
-
as,
|
|
781
|
-
this._tableAlias,
|
|
782
|
-
]));
|
|
676
|
+
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [column, enums_1.ColumnMethods.SUM, as, this._tableAlias]));
|
|
783
677
|
return this;
|
|
784
678
|
}
|
|
785
679
|
avg(column, as) {
|
|
786
|
-
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [
|
|
787
|
-
column,
|
|
788
|
-
enums_1.ColumnMethods.AVG,
|
|
789
|
-
as,
|
|
790
|
-
this._tableAlias,
|
|
791
|
-
]));
|
|
680
|
+
this._columns.push(this._container.resolve(statements_1.ColumnMethodStatement, [column, enums_1.ColumnMethods.AVG, as, this._tableAlias]));
|
|
792
681
|
return this;
|
|
793
682
|
}
|
|
794
683
|
distinct() {
|
|
@@ -822,7 +711,7 @@ class SelectQueryBuilder extends QueryBuilder {
|
|
|
822
711
|
}
|
|
823
712
|
}
|
|
824
713
|
__decorate([
|
|
825
|
-
typescript_mix_1.use(WhereBuilder, LimitBuilder, OrderByBuilder, ColumnsBuilder, JoinBuilder, WithRecursiveBuilder, GroupByBuilder),
|
|
714
|
+
(0, typescript_mix_1.use)(WhereBuilder, LimitBuilder, OrderByBuilder, ColumnsBuilder, JoinBuilder, WithRecursiveBuilder, GroupByBuilder),
|
|
826
715
|
__metadata("design:type", Object)
|
|
827
716
|
], SelectQueryBuilder.prototype, "this", void 0);
|
|
828
717
|
exports.SelectQueryBuilder = SelectQueryBuilder;
|
|
@@ -843,9 +732,7 @@ class DeleteQueryBuilder extends QueryBuilder {
|
|
|
843
732
|
return this._truncate;
|
|
844
733
|
}
|
|
845
734
|
toDB() {
|
|
846
|
-
return this._container
|
|
847
|
-
.resolve(interfaces_1.DeleteQueryCompiler, [this])
|
|
848
|
-
.compile();
|
|
735
|
+
return this._container.resolve(interfaces_1.DeleteQueryCompiler, [this]).compile();
|
|
849
736
|
}
|
|
850
737
|
truncate() {
|
|
851
738
|
this._truncate = true;
|
|
@@ -853,7 +740,7 @@ class DeleteQueryBuilder extends QueryBuilder {
|
|
|
853
740
|
}
|
|
854
741
|
}
|
|
855
742
|
__decorate([
|
|
856
|
-
typescript_mix_1.use(WhereBuilder, LimitBuilder),
|
|
743
|
+
(0, typescript_mix_1.use)(WhereBuilder, LimitBuilder),
|
|
857
744
|
__metadata("design:type", Object)
|
|
858
745
|
], DeleteQueryBuilder.prototype, "this", void 0);
|
|
859
746
|
exports.DeleteQueryBuilder = DeleteQueryBuilder;
|
|
@@ -905,13 +792,11 @@ class UpdateQueryBuilder extends QueryBuilder {
|
|
|
905
792
|
return this;
|
|
906
793
|
}
|
|
907
794
|
toDB() {
|
|
908
|
-
return this._container
|
|
909
|
-
.resolve(interfaces_1.UpdateQueryCompiler, [this])
|
|
910
|
-
.compile();
|
|
795
|
+
return this._container.resolve(interfaces_1.UpdateQueryCompiler, [this]).compile();
|
|
911
796
|
}
|
|
912
797
|
}
|
|
913
798
|
__decorate([
|
|
914
|
-
typescript_mix_1.use(WhereBuilder),
|
|
799
|
+
(0, typescript_mix_1.use)(WhereBuilder),
|
|
915
800
|
__metadata("design:type", Object)
|
|
916
801
|
], UpdateQueryBuilder.prototype, "this", void 0);
|
|
917
802
|
exports.UpdateQueryBuilder = UpdateQueryBuilder;
|
|
@@ -939,11 +824,7 @@ class InsertQueryBuilder extends QueryBuilder {
|
|
|
939
824
|
values(data) {
|
|
940
825
|
const self = this;
|
|
941
826
|
if (Array.isArray(data)) {
|
|
942
|
-
this.columns(_.chain(data)
|
|
943
|
-
.map(_.keys)
|
|
944
|
-
.flatten()
|
|
945
|
-
.uniq()
|
|
946
|
-
.value());
|
|
827
|
+
this.columns(_.chain(data).map(_.keys).flatten().uniq().value());
|
|
947
828
|
data.forEach((d) => {
|
|
948
829
|
_addData(d);
|
|
949
830
|
});
|
|
@@ -955,8 +836,8 @@ class InsertQueryBuilder extends QueryBuilder {
|
|
|
955
836
|
function _addData(d) {
|
|
956
837
|
const binding = [];
|
|
957
838
|
self._columns
|
|
958
|
-
.filter(c => !(c.Column instanceof RawQuery))
|
|
959
|
-
.map(c => {
|
|
839
|
+
.filter((c) => !(c.Column instanceof RawQuery))
|
|
840
|
+
.map((c) => {
|
|
960
841
|
return c.Column;
|
|
961
842
|
})
|
|
962
843
|
.forEach((c) => {
|
|
@@ -972,20 +853,20 @@ class InsertQueryBuilder extends QueryBuilder {
|
|
|
972
853
|
}
|
|
973
854
|
onDuplicate(column) {
|
|
974
855
|
let columnToCheck = column;
|
|
975
|
-
if (!columnToCheck) {
|
|
976
|
-
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);
|
|
977
860
|
}
|
|
978
861
|
this.DuplicateQueryBuilder = new OnDuplicateQueryBuilder(this._container, this, columnToCheck);
|
|
979
862
|
return this.DuplicateQueryBuilder;
|
|
980
863
|
}
|
|
981
864
|
toDB() {
|
|
982
|
-
return this._container
|
|
983
|
-
.resolve(interfaces_1.InsertQueryCompiler, [this])
|
|
984
|
-
.compile();
|
|
865
|
+
return this._container.resolve(interfaces_1.InsertQueryCompiler, [this]).compile();
|
|
985
866
|
}
|
|
986
867
|
}
|
|
987
868
|
__decorate([
|
|
988
|
-
typescript_mix_1.use(ColumnsBuilder),
|
|
869
|
+
(0, typescript_mix_1.use)(ColumnsBuilder),
|
|
989
870
|
__metadata("design:type", Object)
|
|
990
871
|
], InsertQueryBuilder.prototype, "this", void 0);
|
|
991
872
|
exports.InsertQueryBuilder = InsertQueryBuilder;
|
|
@@ -1011,14 +892,12 @@ let IndexQueryBuilder = class IndexQueryBuilder extends Builder {
|
|
|
1011
892
|
return this;
|
|
1012
893
|
}
|
|
1013
894
|
toDB() {
|
|
1014
|
-
return this._container
|
|
1015
|
-
.resolve(interfaces_1.IndexQueryCompiler, [this])
|
|
1016
|
-
.compile();
|
|
895
|
+
return this._container.resolve(interfaces_1.IndexQueryCompiler, [this]).compile();
|
|
1017
896
|
}
|
|
1018
897
|
};
|
|
1019
898
|
IndexQueryBuilder = __decorate([
|
|
1020
|
-
di_1.NewInstance(),
|
|
1021
|
-
di_1.Inject(di_1.Container),
|
|
899
|
+
(0, di_1.NewInstance)(),
|
|
900
|
+
(0, di_1.Inject)(di_1.Container),
|
|
1022
901
|
__metadata("design:paramtypes", [di_1.Container, driver_1.OrmDriver])
|
|
1023
902
|
], IndexQueryBuilder);
|
|
1024
903
|
exports.IndexQueryBuilder = IndexQueryBuilder;
|
|
@@ -1031,7 +910,7 @@ let ForeignKeyBuilder = class ForeignKeyBuilder {
|
|
|
1031
910
|
*
|
|
1032
911
|
* Referenced field in child table
|
|
1033
912
|
*
|
|
1034
|
-
* @param fkName name of foreign field in child table
|
|
913
|
+
* @param fkName - name of foreign field in child table
|
|
1035
914
|
*/
|
|
1036
915
|
foreignKey(fkName) {
|
|
1037
916
|
this.ForeignKeyField = fkName;
|
|
@@ -1041,8 +920,8 @@ let ForeignKeyBuilder = class ForeignKeyBuilder {
|
|
|
1041
920
|
*
|
|
1042
921
|
* Referenced parent table & key
|
|
1043
922
|
*
|
|
1044
|
-
* @param table parent table
|
|
1045
|
-
* @param pKey parant table key field
|
|
923
|
+
* @param table - parent table
|
|
924
|
+
* @param pKey - parant table key field
|
|
1046
925
|
*/
|
|
1047
926
|
references(table, pKey) {
|
|
1048
927
|
this.Table = table;
|
|
@@ -1053,7 +932,7 @@ let ForeignKeyBuilder = class ForeignKeyBuilder {
|
|
|
1053
932
|
*
|
|
1054
933
|
* On delete action
|
|
1055
934
|
*
|
|
1056
|
-
* @param action action to take on delete
|
|
935
|
+
* @param action - action to take on delete
|
|
1057
936
|
*/
|
|
1058
937
|
onDelete(action) {
|
|
1059
938
|
this.OnDeleteAction = action;
|
|
@@ -1063,7 +942,7 @@ let ForeignKeyBuilder = class ForeignKeyBuilder {
|
|
|
1063
942
|
*
|
|
1064
943
|
* On update action
|
|
1065
944
|
*
|
|
1066
|
-
* @param action action to take on update
|
|
945
|
+
* @param action - action to take on update
|
|
1067
946
|
*/
|
|
1068
947
|
onUpdate(action) {
|
|
1069
948
|
this.OnUpdateAction = action;
|
|
@@ -1079,7 +958,7 @@ let ForeignKeyBuilder = class ForeignKeyBuilder {
|
|
|
1079
958
|
}
|
|
1080
959
|
};
|
|
1081
960
|
ForeignKeyBuilder = __decorate([
|
|
1082
|
-
di_1.NewInstance(),
|
|
961
|
+
(0, di_1.NewInstance)(),
|
|
1083
962
|
__metadata("design:paramtypes", [])
|
|
1084
963
|
], ForeignKeyBuilder);
|
|
1085
964
|
exports.ForeignKeyBuilder = ForeignKeyBuilder;
|
|
@@ -1136,7 +1015,7 @@ let ColumnQueryBuilder = class ColumnQueryBuilder {
|
|
|
1136
1015
|
}
|
|
1137
1016
|
};
|
|
1138
1017
|
ColumnQueryBuilder = __decorate([
|
|
1139
|
-
di_1.NewInstance(),
|
|
1018
|
+
(0, di_1.NewInstance)(),
|
|
1140
1019
|
__metadata("design:paramtypes", [String, String, Object])
|
|
1141
1020
|
], ColumnQueryBuilder);
|
|
1142
1021
|
exports.ColumnQueryBuilder = ColumnQueryBuilder;
|
|
@@ -1157,10 +1036,7 @@ class TableQueryBuilder extends QueryBuilder {
|
|
|
1157
1036
|
return this._foreignKeys;
|
|
1158
1037
|
}
|
|
1159
1038
|
increments(name) {
|
|
1160
|
-
return this.int(name)
|
|
1161
|
-
.autoIncrement()
|
|
1162
|
-
.notNull()
|
|
1163
|
-
.primaryKey();
|
|
1039
|
+
return this.int(name).autoIncrement().notNull().primaryKey();
|
|
1164
1040
|
}
|
|
1165
1041
|
comment(comment) {
|
|
1166
1042
|
this._comment = comment;
|
|
@@ -1175,9 +1051,7 @@ class TableQueryBuilder extends QueryBuilder {
|
|
|
1175
1051
|
return builder;
|
|
1176
1052
|
}
|
|
1177
1053
|
toDB() {
|
|
1178
|
-
return this._container
|
|
1179
|
-
.resolve(interfaces_1.TableQueryCompiler, [this])
|
|
1180
|
-
.compile();
|
|
1054
|
+
return this._container.resolve(interfaces_1.TableQueryCompiler, [this]).compile();
|
|
1181
1055
|
}
|
|
1182
1056
|
}
|
|
1183
1057
|
exports.TableQueryBuilder = TableQueryBuilder;
|
|
@@ -1193,12 +1067,12 @@ let SchemaQueryBuilder = class SchemaQueryBuilder {
|
|
|
1193
1067
|
}
|
|
1194
1068
|
};
|
|
1195
1069
|
SchemaQueryBuilder = __decorate([
|
|
1196
|
-
di_1.NewInstance(),
|
|
1197
|
-
di_1.Inject(di_1.Container),
|
|
1070
|
+
(0, di_1.NewInstance)(),
|
|
1071
|
+
(0, di_1.Inject)(di_1.Container),
|
|
1198
1072
|
__metadata("design:paramtypes", [di_1.Container, driver_1.OrmDriver])
|
|
1199
1073
|
], SchemaQueryBuilder);
|
|
1200
1074
|
exports.SchemaQueryBuilder = SchemaQueryBuilder;
|
|
1201
|
-
Object.values(enums_1.ColumnType).forEach(type => {
|
|
1075
|
+
Object.values(enums_1.ColumnType).forEach((type) => {
|
|
1202
1076
|
TableQueryBuilder.prototype[type] = function (name, ...args) {
|
|
1203
1077
|
const _builder = new ColumnQueryBuilder(name, type, ...args);
|
|
1204
1078
|
this._columns.push(_builder);
|