@axiosleo/orm-mysql 0.9.16 → 0.9.17
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 +2 -2
- package/package.json +1 -1
- package/src/builder.js +18 -0
package/bin/orm-mysql.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -22,8 +22,8 @@ export type Clients = {
|
|
|
22
22
|
export type ConditionValueType = null | string | number | boolean | Date | Array<string | number | boolean | Date> | Query;
|
|
23
23
|
|
|
24
24
|
export type OptType = '=' | '!=' | '>' | '<' | '>=' | '<=' |
|
|
25
|
-
'LIKE' | 'NOT LIKE' | 'IN' | 'NOT IN' | 'BETWEEN' | 'NOT BETWEEN' | 'IS' | 'IS NOT' | 'REGEXP' | 'NOT REGEXP' | 'AND' | 'OR' | 'GROUP' | 'CONTAIN' | 'NOT
|
|
26
|
-
'like' | 'not like' | 'in' | 'not in' | 'between' | 'not between' | 'is' | 'is not' | 'regexp' | 'not regexp' | 'and' | 'or' | 'group' | 'contain' | 'not contain';
|
|
25
|
+
'LIKE' | 'NOT LIKE' | 'IN' | 'NOT IN' | 'BETWEEN' | 'NOT BETWEEN' | 'IS' | 'IS NOT' | 'REGEXP' | 'NOT REGEXP' | 'AND' | 'OR' | 'GROUP' | 'CONTAIN' | 'NOT CONTAIN' | 'OVERLAPS' | 'NOT OVERLAPS' |
|
|
26
|
+
'like' | 'not like' | 'in' | 'not in' | 'between' | 'not between' | 'is' | 'is not' | 'regexp' | 'not regexp' | 'and' | 'or' | 'group' | 'contain' | 'not contain' | 'overlaps' | 'not overlaps';
|
|
27
27
|
|
|
28
28
|
export interface WhereOptions {
|
|
29
29
|
key: string | null;
|
package/package.json
CHANGED
package/src/builder.js
CHANGED
|
@@ -295,6 +295,20 @@ class Builder {
|
|
|
295
295
|
return res ? `${this._buildFieldKey(condition.key)} ${opt} CONCAT('%', ?, '%')` : `${this._buildFieldKey(condition.key)} ${opt} CONCAT('%', ?, '%')`;
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
+
_buildConditionOverlaps(condition, isNot = false) {
|
|
299
|
+
if (condition.key.indexOf('->') !== -1) {
|
|
300
|
+
let keys = condition.key.split('->');
|
|
301
|
+
let k = `${this._buildFieldKey(keys[0])}`;
|
|
302
|
+
let res = this._buildConditionValues(condition.value);
|
|
303
|
+
let sql = res ? `JSON_OVERLAPS(JSON_EXTRACT(${k}, '${keys[1]}'), JSON_ARRAY(${res}))` :
|
|
304
|
+
`JSON_OVERLAPS(JSON_EXTRACT(${k}, '${keys[1]}'), JSON_ARRAY(?))`;
|
|
305
|
+
return isNot ? `${sql}=0` : sql;
|
|
306
|
+
}
|
|
307
|
+
let res = this._buildConditionValues(condition.value);
|
|
308
|
+
const opt = isNot ? 'NOT REGEXP' : 'REGEXP';
|
|
309
|
+
return res ? `${this._buildFieldKey(condition.key)} ${opt} ?` : `${this._buildFieldKey(condition.key)} ${opt} ?`;
|
|
310
|
+
}
|
|
311
|
+
|
|
298
312
|
_buildCondition(conditions, prefix) {
|
|
299
313
|
if (!conditions || !conditions.length) {
|
|
300
314
|
return '';
|
|
@@ -315,6 +329,10 @@ class Builder {
|
|
|
315
329
|
return this._buildConditionContain(c);
|
|
316
330
|
} else if (opt === 'not contain') {
|
|
317
331
|
return this._buildConditionContain(c, true);
|
|
332
|
+
} else if (opt === 'overlaps') {
|
|
333
|
+
return this._buildConditionOverlaps(c);
|
|
334
|
+
} else if (opt === 'not overlaps') {
|
|
335
|
+
return this._buildConditionOverlaps(c, true);
|
|
318
336
|
}
|
|
319
337
|
if (c.key && c.key.indexOf('->') !== -1) {
|
|
320
338
|
const keys = c.key.split('->');
|