@axiosleo/orm-mysql 0.5.1 → 0.5.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.
- package/package.json +1 -1
- package/src/builder.js +19 -3
package/package.json
CHANGED
package/src/builder.js
CHANGED
|
@@ -192,6 +192,21 @@ class Builder {
|
|
|
192
192
|
return null;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
_buildContidionIn(condition, isNot = false) {
|
|
196
|
+
if (!Array.isArray(condition.value) && !(condition.value instanceof Query)) {
|
|
197
|
+
throw new Error('Value must be an array for "IN" condition');
|
|
198
|
+
}
|
|
199
|
+
if (condition.key.indexOf('$') !== -1) {
|
|
200
|
+
let res = this._buildConditionValues(condition.value);
|
|
201
|
+
let sql = res ? `JSON_CONTAINS(JSON_ARRAY(${res}), ${this._buildFieldKey(condition.key)})` :
|
|
202
|
+
`JSON_CONTAINS(JSON_ARRAY(?), ${this._buildFieldKey(condition.key)})`;
|
|
203
|
+
return isNot ? `${sql}=0` : sql;
|
|
204
|
+
}
|
|
205
|
+
let res = this._buildConditionValues(condition.value);
|
|
206
|
+
const opt = isNot ? 'NOT IN' : 'IN';
|
|
207
|
+
return res ? `${this._buildFieldKey(condition.key)} ${opt} (${res})` : `${this._buildFieldKey(condition.key)} ${opt} (?)`;
|
|
208
|
+
}
|
|
209
|
+
|
|
195
210
|
_buildContidion(conditions, prefix) {
|
|
196
211
|
if (!conditions || !conditions.length) {
|
|
197
212
|
return '';
|
|
@@ -216,9 +231,10 @@ class Builder {
|
|
|
216
231
|
], '');
|
|
217
232
|
}
|
|
218
233
|
const opt = c.opt.toLowerCase();
|
|
219
|
-
if (opt === 'in'
|
|
220
|
-
|
|
221
|
-
|
|
234
|
+
if (opt === 'in') {
|
|
235
|
+
return this._buildContidionIn(c);
|
|
236
|
+
} else if (opt === 'not in') {
|
|
237
|
+
return this._buildContidionIn(c, true);
|
|
222
238
|
} else if (opt === 'group' && Array.isArray(c.value)) {
|
|
223
239
|
return `(${this._buildContidion(c.value, '')})`;
|
|
224
240
|
}
|