mythix-orm-sql-base 1.4.3 → 1.4.4

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.
@@ -65,6 +65,14 @@ class SQLConnectionBase extends ConnectionBase {
65
65
  }
66
66
  }
67
67
 
68
+ databaseSupportsLimitInSubQuery() {
69
+ return false;
70
+ }
71
+
72
+ databaseSupportsOrderInSubQuery() {
73
+ return false;
74
+ }
75
+
68
76
  prepareArrayValuesForSQL(_array) {
69
77
  let array = Nife.arrayFlatten(_array);
70
78
 
@@ -84,17 +92,6 @@ class SQLConnectionBase extends ConnectionBase {
84
92
  return Nife.uniq(array);
85
93
  }
86
94
 
87
- getDefaultOrder(Model, options) {
88
- let order = Nife.toArray(Model.getDefaultOrder(options));
89
-
90
- order = Nife.arrayFlatten(order).filter(Boolean);
91
-
92
- if (Nife.isEmpty(order))
93
- return;
94
-
95
- return order;
96
- }
97
-
98
95
  generateSavePointName() {
99
96
  let id = UUID.v4();
100
97
 
@@ -527,21 +527,32 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
527
527
  let sqlParts = [];
528
528
 
529
529
  if (Nife.isNotEmpty(order)) {
530
- let result = this.generateOrderClause(order, options);
531
- if (result)
532
- sqlParts.push(result);
530
+ if (!(options && options.isSubQuery) || (options && options.isSubQuery && this.connection.databaseSupportsOrderInSubQuery())) {
531
+ let result = this.generateOrderClause(order, options);
532
+ if (result)
533
+ sqlParts.push(result);
534
+
535
+ if (!(Nife.instanceOf(limit, 'number') && isFinite(limit)) && options && options.forceLimit) {
536
+ limit = options.forceLimit;
537
+ offset = 0;
538
+ }
539
+ }
533
540
  }
534
541
 
535
542
  if (!Object.is(limit, Infinity) && Nife.isNotEmpty(limit)) {
536
- let result = this.generateLimitClause(limit, options);
537
- if (result)
538
- sqlParts.push(result);
543
+ if (!(options && options.isSubQuery) || (options && options.isSubQuery && this.connection.databaseSupportsLimitInSubQuery())) {
544
+ let result = this.generateLimitClause(limit, options);
545
+ if (result)
546
+ sqlParts.push(result);
547
+ }
539
548
  }
540
549
 
541
550
  if (Nife.isNotEmpty(offset)) {
542
- let result = this.generateOffsetClause(offset, options);
543
- if (result)
544
- sqlParts.push(result);
551
+ if (!(options && options.isSubQuery) || (options && options.isSubQuery && this.connection.databaseSupportsLimitInSubQuery())) {
552
+ let result = this.generateOffsetClause(offset, options);
553
+ if (result)
554
+ sqlParts.push(result);
555
+ }
545
556
  }
546
557
 
547
558
  return sqlParts.join(' ');
@@ -1071,9 +1082,10 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
1071
1082
  queryEngine = queryEngine.PROJECT(`${Model.getModelName()}:${pkField.fieldName}`);
1072
1083
 
1073
1084
  let innerSelect = this.generateSelectStatement(queryEngine, this.stackAssign(options, { isSubQuery: true, noProjectionAliases: true }));
1085
+ let orderLimitOffset = this.generateSelectOrderLimitOffset(queryEngine, this.stackAssign(options, { forceLimit: 4294967294 }));
1074
1086
  let escapedColumnName = this.getEscapedColumnName(Model, pkField, options);
1075
1087
 
1076
- return `DELETE FROM ${escapedTableName} WHERE ${escapedColumnName} IN (${innerSelect})`;
1088
+ return `DELETE FROM ${escapedTableName} WHERE ${escapedColumnName} IN (${innerSelect})${(orderLimitOffset) ? ` ${orderLimitOffset}` : ''}`;
1077
1089
  } else {
1078
1090
  return `DELETE FROM ${escapedTableName}${(where) ? ` ${where}` : ''}`;
1079
1091
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mythix-orm-sql-base",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "SQL base support for Mythix ORM",
5
5
  "main": "lib/index.js",
6
6
  "type": "commonjs",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "homepage": "https://github.com/th317erd/mythix-orm-sql-base#readme",
35
35
  "peerDependencies": {
36
- "mythix-orm": "^1.5.2"
36
+ "mythix-orm": "^1.5.5"
37
37
  },
38
38
  "dependencies": {
39
39
  "nife": "^1.11.3",