@axiosleo/orm-mysql 0.9.14 → 0.9.16
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/bin/orm-mysql.js +1 -1
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/builder.js +34 -28
package/bin/orm-mysql.js
CHANGED
package/index.d.ts
CHANGED
package/package.json
CHANGED
package/src/builder.js
CHANGED
|
@@ -268,10 +268,12 @@ class Builder {
|
|
|
268
268
|
} else if (!Array.isArray(condition.value) && !(condition.value instanceof Query)) {
|
|
269
269
|
throw new Error('Value must be an array or sub-query for "IN" condition');
|
|
270
270
|
}
|
|
271
|
-
if (condition.key.indexOf('
|
|
271
|
+
if (condition.key.indexOf('->') !== -1) {
|
|
272
|
+
let keys = condition.key.split('->');
|
|
273
|
+
let k = `${this._buildFieldKey(keys[0])}`;
|
|
272
274
|
let res = this._buildConditionValues(condition.value);
|
|
273
|
-
let sql = res ? `JSON_CONTAINS(JSON_ARRAY(${res}), ${
|
|
274
|
-
`JSON_CONTAINS(JSON_ARRAY(?), ${
|
|
275
|
+
let sql = res ? `JSON_CONTAINS(JSON_ARRAY(${res}), JSON_EXTRACT(${k}, '${keys[1]}'))` :
|
|
276
|
+
`JSON_CONTAINS(JSON_ARRAY(?), JSON_EXTRACT(${k}, '${keys[1]}'))`;
|
|
275
277
|
return isNot ? `${sql}=0` : sql;
|
|
276
278
|
}
|
|
277
279
|
let res = this._buildConditionValues(condition.value);
|
|
@@ -280,10 +282,12 @@ class Builder {
|
|
|
280
282
|
}
|
|
281
283
|
|
|
282
284
|
_buildConditionContain(condition, isNot = false) {
|
|
283
|
-
if (condition.key.indexOf('
|
|
285
|
+
if (condition.key.indexOf('->') !== -1) {
|
|
286
|
+
let keys = condition.key.split('->');
|
|
287
|
+
let k = `${this._buildFieldKey(keys[0])}`;
|
|
284
288
|
let res = this._buildConditionValues(condition.value);
|
|
285
|
-
let sql = res ? `JSON_CONTAINS(${
|
|
286
|
-
`JSON_CONTAINS(${
|
|
289
|
+
let sql = res ? `JSON_CONTAINS(${k}, JSON_ARRAY(${res}), '${keys[1]}')` :
|
|
290
|
+
`JSON_CONTAINS(${k}, JSON_ARRAY(?), '${keys[1]}')`;
|
|
287
291
|
return isNot ? `${sql}=0` : sql;
|
|
288
292
|
}
|
|
289
293
|
let res = this._buildConditionValues(condition.value);
|
|
@@ -297,18 +301,20 @@ class Builder {
|
|
|
297
301
|
}
|
|
298
302
|
let sql = typeof prefix === 'undefined' ? 'WHERE ' : prefix;
|
|
299
303
|
if (conditions.length) {
|
|
300
|
-
sql += `${conditions.map((c) => {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
c.value = null;
|
|
306
|
-
}
|
|
307
|
-
if (c.key === null && c.value === null) {
|
|
308
|
-
return ` ${c.opt} `;
|
|
304
|
+
sql += `${conditions.map((c, index) => {
|
|
305
|
+
const opt = c.opt.toLowerCase();
|
|
306
|
+
if (opt === 'group' && Array.isArray(c.value)) {
|
|
307
|
+
let t = `(${this._buildCondition(c.value, '')})`;
|
|
308
|
+
return index === 0 ? t : ` AND ${t}`;
|
|
309
309
|
}
|
|
310
|
-
if (
|
|
311
|
-
return
|
|
310
|
+
if (opt === 'in') {
|
|
311
|
+
return this._buildConditionIn(c);
|
|
312
|
+
} else if (opt === 'not in') {
|
|
313
|
+
return this._buildConditionIn(c, true);
|
|
314
|
+
} else if (opt === 'contain') {
|
|
315
|
+
return this._buildConditionContain(c);
|
|
316
|
+
} else if (opt === 'not contain') {
|
|
317
|
+
return this._buildConditionContain(c, true);
|
|
312
318
|
}
|
|
313
319
|
if (c.key && c.key.indexOf('->') !== -1) {
|
|
314
320
|
const keys = c.key.split('->');
|
|
@@ -320,17 +326,17 @@ class Builder {
|
|
|
320
326
|
}
|
|
321
327
|
], '');
|
|
322
328
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
return this.
|
|
329
|
+
if (typeof c.key === 'undefined') {
|
|
330
|
+
c.key = null;
|
|
331
|
+
}
|
|
332
|
+
if (typeof c.value === 'undefined') {
|
|
333
|
+
c.value = null;
|
|
334
|
+
}
|
|
335
|
+
if (c.key === null && c.value === null) {
|
|
336
|
+
return ` ${c.opt} `;
|
|
337
|
+
}
|
|
338
|
+
if (c.value === null) {
|
|
339
|
+
return c.opt === '=' ? `ISNULL(${this._buildFieldKey(c.key)})` : `!ISNULL(${this._buildFieldKey(c.key)})`;
|
|
334
340
|
}
|
|
335
341
|
let res = this._buildConditionValues(c.value);
|
|
336
342
|
if (!is.empty(res)) {
|