mythix-orm-sql-base 1.2.0 → 1.3.0
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.
|
@@ -117,7 +117,7 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
// eslint-disable-next-line no-unused-vars
|
|
120
|
-
generateSelectQueryOperatorFromQueryEngineOperator(operator, value, valueIsReference, options) {
|
|
120
|
+
generateSelectQueryOperatorFromQueryEngineOperator(queryPart, operator, value, valueIsReference, options) {
|
|
121
121
|
if (LiteralBase.isLiteral(operator))
|
|
122
122
|
return operator.toString(this.connection);
|
|
123
123
|
|
|
@@ -148,11 +148,36 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
|
|
|
148
148
|
return '<';
|
|
149
149
|
case 'LTE':
|
|
150
150
|
return '<=';
|
|
151
|
+
case 'LIKE':
|
|
152
|
+
if (valueIsReference)
|
|
153
|
+
throw new TypeError(`${this.constructor.name}::generateSelectQueryOperatorFromQueryEngineOperator: The "LIKE" operator can not be used for table joins.`);
|
|
154
|
+
|
|
155
|
+
if (!Nife.instanceOf(value, 'string'))
|
|
156
|
+
throw new TypeError(`${this.constructor.name}::generateSelectQueryOperatorFromQueryEngineOperator: The "LIKE" operator requires a string for a value.`);
|
|
157
|
+
|
|
158
|
+
return 'LIKE';
|
|
159
|
+
case 'NOT_LIKE':
|
|
160
|
+
if (valueIsReference)
|
|
161
|
+
throw new TypeError(`${this.constructor.name}::generateSelectQueryOperatorFromQueryEngineOperator: The "NOT LIKE" operator can not be used for table joins.`);
|
|
162
|
+
|
|
163
|
+
if (!Nife.instanceOf(value, 'string'))
|
|
164
|
+
throw new TypeError(`${this.constructor.name}::generateSelectQueryOperatorFromQueryEngineOperator: The "NOT LIKE" operator requires a string for a value.`);
|
|
165
|
+
|
|
166
|
+
return 'NOT LIKE';
|
|
151
167
|
default:
|
|
152
168
|
throw new Error(`${this.constructor.name}::generateSelectQueryOperatorFromQueryEngineOperator: Unknown operator "${operator}".`);
|
|
153
169
|
}
|
|
154
170
|
}
|
|
155
171
|
|
|
172
|
+
formatLikeValue({ value }) {
|
|
173
|
+
return value;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// eslint-disable-next-line no-unused-vars
|
|
177
|
+
generateConditionPostfix(context) {
|
|
178
|
+
return '';
|
|
179
|
+
}
|
|
180
|
+
|
|
156
181
|
generateSelectQueryCondition(queryPart, _value, options) {
|
|
157
182
|
let value = _value;
|
|
158
183
|
let field = queryPart.Field;
|
|
@@ -162,6 +187,9 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
|
|
|
162
187
|
// If the value is an array, then handle the
|
|
163
188
|
// special "IN" case for an array
|
|
164
189
|
if (Array.isArray(value)) {
|
|
190
|
+
if (operator !== 'EQ' && operator !== 'NEQ')
|
|
191
|
+
throw new Error(`${this.constructor.name}::generateSelectQueryCondition: Invalid value provided to operator "${operator}": `, value);
|
|
192
|
+
|
|
165
193
|
// Flatten array, filter down to
|
|
166
194
|
// only unique items, and remove
|
|
167
195
|
// anything that we can't match on
|
|
@@ -200,7 +228,7 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
|
|
|
200
228
|
|
|
201
229
|
let escapedTableName = this.escapeID(this.getTableNameFromQueryPart(queryPart));
|
|
202
230
|
let escapedColumnName = this.escapeID(field.columnName);
|
|
203
|
-
let sqlOperator = this.generateSelectQueryOperatorFromQueryEngineOperator(operator, value, false, options);
|
|
231
|
+
let sqlOperator = this.generateSelectQueryOperatorFromQueryEngineOperator(queryPart, operator, value, false, options);
|
|
204
232
|
|
|
205
233
|
if (QueryEngine.isQuery(value)) {
|
|
206
234
|
if (!this.queryHasConditions(value._getRawQuery()))
|
|
@@ -214,7 +242,13 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
|
|
|
214
242
|
return `${escapedTableName}.${escapedColumnName} ${sqlOperator} (${this.generateSelectStatement(value, this.stackAssign(options, { isSubQuery: true }))})`;
|
|
215
243
|
}
|
|
216
244
|
|
|
217
|
-
|
|
245
|
+
let context = { queryPart, field, sqlOperator, operator, value };
|
|
246
|
+
if (sqlOperator === 'LIKE' || sqlOperator === 'NOT LIKE')
|
|
247
|
+
value = this.formatLikeValue(context);
|
|
248
|
+
|
|
249
|
+
let conditionPostfix = this.generateConditionPostfix(context);
|
|
250
|
+
|
|
251
|
+
return `${escapedTableName}.${escapedColumnName} ${sqlOperator} ${this.escape(field, value)}${(conditionPostfix) ? ` ${conditionPostfix}` : ''}`;
|
|
218
252
|
}
|
|
219
253
|
|
|
220
254
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -231,7 +265,7 @@ class SQLQueryGeneratorBase extends QueryGeneratorBase {
|
|
|
231
265
|
let leftSideEscapedColumnName = this.escapeID(leftField.columnName);
|
|
232
266
|
let rightSideEscapedTableName = this.escapeID(this.getTableNameFromQueryPart(rightQueryPart));
|
|
233
267
|
let rightSideEscapedColumnName = this.escapeID(rightField.columnName);
|
|
234
|
-
let sqlOperator = this.generateSelectQueryOperatorFromQueryEngineOperator(operator, undefined, true, options);
|
|
268
|
+
let sqlOperator = this.generateSelectQueryOperatorFromQueryEngineOperator(leftQueryPart, operator, undefined, true, options);
|
|
235
269
|
|
|
236
270
|
return `${leftSideEscapedTableName}.${leftSideEscapedColumnName} ${sqlOperator} ${rightSideEscapedTableName}.${rightSideEscapedColumnName}`;
|
|
237
271
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mythix-orm-sql-base",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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.4.
|
|
36
|
+
"mythix-orm": "^1.4.4"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"nife": "^1.11.3",
|