mythix-orm 1.11.0 → 1.11.1
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.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
|
|
|
@@ -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
|
|