mythix-orm 1.11.0 → 1.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.
|
@@ -50,14 +50,78 @@ function applyOrderClause(extraData, ...args) {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
function wrapOrderClause(func) {
|
|
53
|
-
|
|
53
|
+
const applyQueryOrder = (_order, replace) => {
|
|
54
|
+
let query = this;
|
|
55
|
+
let order = Nife.arrayFlatten(Nife.toArray(_order).filter(Boolean));
|
|
56
|
+
|
|
57
|
+
let asc = order.filter((thisOrder) => {
|
|
58
|
+
if (!Nife.instanceOf(thisOrder, 'string'))
|
|
59
|
+
return true;
|
|
60
|
+
|
|
61
|
+
if (thisOrder.charAt(0) === '-')
|
|
62
|
+
return false;
|
|
63
|
+
|
|
64
|
+
return true;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
let desc = order.filter((thisOrder) => {
|
|
68
|
+
if (!Nife.instanceOf(thisOrder, 'string'))
|
|
69
|
+
return false;
|
|
70
|
+
|
|
71
|
+
if (thisOrder.charAt(0) !== '-')
|
|
72
|
+
return false;
|
|
73
|
+
|
|
74
|
+
return true;
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (Nife.isNotEmpty(asc)) {
|
|
78
|
+
asc = asc.map((thisOrder) => {
|
|
79
|
+
if (!Nife.instanceOf(thisOrder, 'string'))
|
|
80
|
+
return thisOrder;
|
|
81
|
+
|
|
82
|
+
return thisOrder.replace(/^\+/, '');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// eslint-disable-next-line new-cap
|
|
86
|
+
query = (replace) ? ASC(asc) : ASC('+', asc);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (Nife.isNotEmpty(desc)) {
|
|
90
|
+
desc = desc.map((thisOrder) => {
|
|
91
|
+
if (!Nife.instanceOf(thisOrder, 'string'))
|
|
92
|
+
return thisOrder;
|
|
93
|
+
|
|
94
|
+
return thisOrder.replace(/^-/, '');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// eslint-disable-next-line new-cap
|
|
98
|
+
query = (replace) ? DESC(desc) : DESC('+', desc);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return query;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const DESC = (...args) => {
|
|
54
105
|
return applyOrderClause.call(this, { direction: '-' }, ...args);
|
|
55
106
|
};
|
|
56
107
|
|
|
57
|
-
|
|
108
|
+
const ASC = (...args) => {
|
|
58
109
|
return applyOrderClause.call(this, { direction: '+' }, ...args);
|
|
59
110
|
};
|
|
60
111
|
|
|
112
|
+
const ADD = (...args) => {
|
|
113
|
+
return applyQueryOrder(args, false);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const REPLACE = (...args) => {
|
|
117
|
+
return applyQueryOrder(args, true);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
func.DESC = DESC;
|
|
121
|
+
func.ASC = ASC;
|
|
122
|
+
func.ADD = ADD;
|
|
123
|
+
func.REPLACE = REPLACE;
|
|
124
|
+
|
|
61
125
|
return func;
|
|
62
126
|
}
|
|
63
127
|
|
|
@@ -239,7 +303,7 @@ class ModelScope extends QueryEngineBase {
|
|
|
239
303
|
|
|
240
304
|
if (!Nife.instanceOf(value, 'string')) {
|
|
241
305
|
console.log(entities);
|
|
242
|
-
throw new
|
|
306
|
+
throw new TypeError(`QueryEngine::ModelScope::PROJECT: Invalid value provided [${value.toString()}]. All values provided must be strings, fields, models, or literals.`);
|
|
243
307
|
}
|
|
244
308
|
|
|
245
309
|
return value;
|
|
@@ -264,10 +328,11 @@ class ModelScope extends QueryEngineBase {
|
|
|
264
328
|
return this._fetchScope('model');
|
|
265
329
|
}
|
|
266
330
|
|
|
267
|
-
DISTINCT = ProxyClass.autoCall(function(
|
|
268
|
-
let
|
|
269
|
-
let
|
|
270
|
-
let
|
|
331
|
+
DISTINCT = ProxyClass.autoCall(function(_fullyQualifiedName) {
|
|
332
|
+
let fullyQualifiedName = _fullyQualifiedName;
|
|
333
|
+
let currentQuery = this;
|
|
334
|
+
let distinctValue = fullyQualifiedName;
|
|
335
|
+
let context = this.getOperationContext();
|
|
271
336
|
|
|
272
337
|
if (arguments.length === 0) {
|
|
273
338
|
let rootModel = context.rootModel;
|
|
@@ -279,8 +344,17 @@ class ModelScope extends QueryEngineBase {
|
|
|
279
344
|
|
|
280
345
|
if (!distinctValue)
|
|
281
346
|
distinctValue = new DistinctLiteral();
|
|
282
|
-
} else if (fullyQualifiedName) {
|
|
347
|
+
} else if (Nife.instanceOf(fullyQualifiedName, 'string')) {
|
|
348
|
+
if (fullyQualifiedName.indexOf(':') < 0)
|
|
349
|
+
fullyQualifiedName = `${context.rootModel.getModelName()}:${fullyQualifiedName}`;
|
|
350
|
+
|
|
351
|
+
distinctValue = new DistinctLiteral(fullyQualifiedName);
|
|
352
|
+
} else if (typeof fullyQualifiedName.isField === 'function' && fullyQualifiedName.isField(fullyQualifiedName)) {
|
|
353
|
+
distinctValue = new DistinctLiteral(`${fullyQualifiedName.Model.getModelName()}:${fullyQualifiedName.fieldName}`);
|
|
354
|
+
} else if (LiteralBase.isLiteral(fullyQualifiedName)) {
|
|
283
355
|
distinctValue = new DistinctLiteral(fullyQualifiedName);
|
|
356
|
+
} else {
|
|
357
|
+
throw new TypeError(`QueryEngine::ModelScope::DISTINCT: Invalid value provided [${(fullyQualifiedName) ? fullyQualifiedName.toString() : fullyQualifiedName}]. All values provided must be strings, fields, or literals.`);
|
|
284
358
|
}
|
|
285
359
|
|
|
286
360
|
currentQuery._pushOperationOntoStack({ sqlFunc: true, operator: 'DISTINCT', queryProp: 'DISTINCT', value: distinctValue, distinct: distinctValue });
|
|
@@ -79,12 +79,22 @@ export declare class QueryEngine<T = ConnectionBase> {
|
|
|
79
79
|
public Field(fieldName: string): QueryEngine;
|
|
80
80
|
public LIMIT(value: number): QueryEngine;
|
|
81
81
|
public OFFSET(value: number): QueryEngine;
|
|
82
|
-
public ORDER(...args: Array<LiteralBase | Field | string | Array<LiteralBase | Field | string>>): QueryEngine;
|
|
83
82
|
public GROUP_BY(...args: Array<LiteralBase | Field | string | Array<LiteralBase | Field | string>>): QueryEngine;
|
|
84
83
|
public HAVING(query: QueryEngine): QueryEngine;
|
|
85
84
|
public EXISTS(query: QueryEngine): QueryEngine;
|
|
86
85
|
public PROJECT(...args: Array<string | ModelClass | LiteralBase | Field | Array<string | ModelClass | LiteralBase | Field>>): QueryEngine;
|
|
87
86
|
|
|
87
|
+
declare public ORDER: {
|
|
88
|
+
(...args: Array<LiteralBase | Field | string | Array<LiteralBase | Field | string>>): QueryEngine;
|
|
89
|
+
|
|
90
|
+
ASC: (...args: Array<LiteralBase | Field | string | Array<LiteralBase | Field | string>>) => QueryEngine;
|
|
91
|
+
DESC: (...args: Array<LiteralBase | Field | string | Array<LiteralBase | Field | string>>) => QueryEngine;
|
|
92
|
+
ADD: (...args: Array<LiteralBase | Field | string | Array<LiteralBase | Field | string>>) => QueryEngine;
|
|
93
|
+
REPLACE: (...args: Array<LiteralBase | Field | string | Array<LiteralBase | Field | string>>) => QueryEngine;
|
|
94
|
+
|
|
95
|
+
name: QueryEngine;
|
|
96
|
+
};
|
|
97
|
+
|
|
88
98
|
declare public NOT: {
|
|
89
99
|
(): QueryEngine;
|
|
90
100
|
|