mythix-orm-sql-base 1.9.4 → 1.9.6
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/lib/sql-query-generator-base.js +48 -26
- package/package.json +2 -2
|
@@ -194,6 +194,12 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
|
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
_getLiteralAlias(literal, options) {
|
|
197
|
+
if (options && options.isSubField)
|
|
198
|
+
return '';
|
|
199
|
+
|
|
200
|
+
if (options && options.noProjectionAliases)
|
|
201
|
+
return '';
|
|
202
|
+
|
|
197
203
|
let as = (literal.options && literal.options.as) || (options && options.as);
|
|
198
204
|
if (Nife.isEmpty(as))
|
|
199
205
|
return '';
|
|
@@ -206,14 +212,14 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
|
|
|
206
212
|
return;
|
|
207
213
|
|
|
208
214
|
let field = literal.getField(this.connection);
|
|
209
|
-
let
|
|
215
|
+
let escapedColumnName;
|
|
210
216
|
|
|
211
217
|
if (LiteralBase.isLiteral(field))
|
|
212
|
-
|
|
218
|
+
escapedColumnName = field.toString(this.connection, this.stackAssign(options, { isSubField: true }));
|
|
213
219
|
else
|
|
214
|
-
|
|
220
|
+
escapedColumnName = this.getEscapedColumnName(field.Model, field, this.stackAssign(options, literal.options));
|
|
215
221
|
|
|
216
|
-
return `AVG(${
|
|
222
|
+
return `AVG(${escapedColumnName})${this._getLiteralAlias(literal, options)}`;
|
|
217
223
|
}
|
|
218
224
|
|
|
219
225
|
_countLiteralToString(literal, options) {
|
|
@@ -221,18 +227,18 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
|
|
|
221
227
|
return;
|
|
222
228
|
|
|
223
229
|
let field = literal.getField(this.connection);
|
|
224
|
-
let
|
|
230
|
+
let escapedColumnName;
|
|
225
231
|
|
|
226
232
|
if (field) {
|
|
227
233
|
if (LiteralBase.isLiteral(field))
|
|
228
|
-
|
|
234
|
+
escapedColumnName = field.toString(this.connection, this.stackAssign(options, { isSubField: true }));
|
|
229
235
|
else
|
|
230
|
-
|
|
236
|
+
escapedColumnName = this.getEscapedColumnName(field.Model, field, this.stackAssign(options, literal.options));
|
|
231
237
|
} else {
|
|
232
|
-
|
|
238
|
+
escapedColumnName = '*';
|
|
233
239
|
}
|
|
234
240
|
|
|
235
|
-
return `COUNT(${
|
|
241
|
+
return `COUNT(${escapedColumnName})${this._getLiteralAlias(literal, options)}`;
|
|
236
242
|
}
|
|
237
243
|
|
|
238
244
|
_distinctLiteralToString(literal, options) {
|
|
@@ -240,13 +246,28 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
|
|
|
240
246
|
return;
|
|
241
247
|
|
|
242
248
|
let field = literal.getField(this.connection);
|
|
249
|
+
if (!field)
|
|
250
|
+
field = literal.valueOf();
|
|
251
|
+
|
|
243
252
|
if (!field)
|
|
244
253
|
return 'DISTINCT';
|
|
245
254
|
|
|
246
|
-
if (LiteralBase.isLiteral(field))
|
|
247
|
-
|
|
255
|
+
if (LiteralBase.isLiteral(field)) {
|
|
256
|
+
let fieldStr = field.toString(this.connection, this.stackAssign(options, { noProjectionAliases: true }));
|
|
257
|
+
if (!fieldStr)
|
|
258
|
+
return '';
|
|
259
|
+
|
|
260
|
+
if (options && options.isSubField)
|
|
261
|
+
return `DISTINCT ${fieldStr}`;
|
|
262
|
+
|
|
263
|
+
return `DISTINCT ON(${fieldStr})`;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
let escapedColumnName = this.getEscapedColumnName(field.Model, field, this.stackAssign(options, literal.options, { noProjectionAliases: true }));
|
|
267
|
+
if (options && options.isSubField)
|
|
268
|
+
return `DISTINCT ${escapedColumnName}`;
|
|
248
269
|
|
|
249
|
-
return `DISTINCT ON(${
|
|
270
|
+
return `DISTINCT ON(${escapedColumnName})`;
|
|
250
271
|
}
|
|
251
272
|
|
|
252
273
|
_fieldLiteralToString(literal, options) {
|
|
@@ -257,7 +278,8 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
|
|
|
257
278
|
if (LiteralBase.isLiteral(field))
|
|
258
279
|
return field.toString(this.connection, options);
|
|
259
280
|
|
|
260
|
-
|
|
281
|
+
let noProjectionAliases = (options && (options.isSubField || !options.isProjection || options.as === false));
|
|
282
|
+
return this.getEscapedProjectionName(field.Model, field, this.stackAssign(options, { noProjectionAliases }, literal.options));
|
|
261
283
|
}
|
|
262
284
|
|
|
263
285
|
_maxLiteralToString(literal, options) {
|
|
@@ -265,14 +287,14 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
|
|
|
265
287
|
return;
|
|
266
288
|
|
|
267
289
|
let field = literal.getField(this.connection);
|
|
268
|
-
let
|
|
290
|
+
let escapedColumnName;
|
|
269
291
|
|
|
270
292
|
if (LiteralBase.isLiteral(field))
|
|
271
|
-
|
|
293
|
+
escapedColumnName = field.toString(this.connection, this.stackAssign(options, { isSubField: true }));
|
|
272
294
|
else
|
|
273
|
-
|
|
295
|
+
escapedColumnName = this.getEscapedColumnName(field.Model, field, this.stackAssign(options, literal.options));
|
|
274
296
|
|
|
275
|
-
return `MAX(${
|
|
297
|
+
return `MAX(${escapedColumnName})${this._getLiteralAlias(literal, options)}`;
|
|
276
298
|
}
|
|
277
299
|
|
|
278
300
|
_minLiteralToString(literal, options) {
|
|
@@ -280,14 +302,14 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
|
|
|
280
302
|
return;
|
|
281
303
|
|
|
282
304
|
let field = literal.getField(this.connection);
|
|
283
|
-
let
|
|
305
|
+
let escapedColumnName;
|
|
284
306
|
|
|
285
307
|
if (LiteralBase.isLiteral(field))
|
|
286
|
-
|
|
308
|
+
escapedColumnName = field.toString(this.connection, this.stackAssign(options, { isSubField: true }));
|
|
287
309
|
else
|
|
288
|
-
|
|
310
|
+
escapedColumnName = this.getEscapedColumnName(field.Model, field, this.stackAssign(options, literal.options));
|
|
289
311
|
|
|
290
|
-
return `MIN(${
|
|
312
|
+
return `MIN(${escapedColumnName})${this._getLiteralAlias(literal, options)}`;
|
|
291
313
|
}
|
|
292
314
|
|
|
293
315
|
_sumLiteralToString(literal, options) {
|
|
@@ -295,14 +317,14 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
|
|
|
295
317
|
return;
|
|
296
318
|
|
|
297
319
|
let field = literal.getField(this.connection);
|
|
298
|
-
let
|
|
320
|
+
let escapedColumnName;
|
|
299
321
|
|
|
300
322
|
if (LiteralBase.isLiteral(field))
|
|
301
|
-
|
|
323
|
+
escapedColumnName = field.toString(this.connection, this.stackAssign(options, { isSubField: true }));
|
|
302
324
|
else
|
|
303
|
-
|
|
325
|
+
escapedColumnName = this.getEscapedColumnName(field.Model, field, this.stackAssign(options, literal.options));
|
|
304
326
|
|
|
305
|
-
return `SUM(${
|
|
327
|
+
return `SUM(${escapedColumnName})${this._getLiteralAlias(literal, options)}`;
|
|
306
328
|
}
|
|
307
329
|
|
|
308
330
|
prepareArrayValuesForSQL(array) {
|
|
@@ -504,7 +526,7 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
|
|
|
504
526
|
if (arrayValues.length > 0)
|
|
505
527
|
subParts.push(this.generateSelectQueryCondition(queryPart, arrayValues, options));
|
|
506
528
|
|
|
507
|
-
return `(${subParts.join(' OR ')})`;
|
|
529
|
+
return `(${subParts.join((operator === 'NEQ') ? ' AND ' : ' OR ')})`;
|
|
508
530
|
}
|
|
509
531
|
|
|
510
532
|
// If no values left in array, then
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mythix-orm-sql-base",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.6",
|
|
4
4
|
"description": "SQL base support for Mythix ORM",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"homepage": "https://github.com/th317erd/mythix-orm-sql-base#readme",
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"mythix-orm": "^1.11.
|
|
37
|
+
"mythix-orm": "^1.11.7"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"luxon": "^3.1.0",
|