@axiosleo/orm-mysql 0.9.13 → 0.9.14
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 +16 -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' |
|
|
26
|
-
'like' | 'not like' | 'in' | 'not in' | 'between' | 'not between' | 'is' | 'is not' | 'regexp' | 'not regexp' | 'and' | 'or' | 'group';
|
|
25
|
+
'LIKE' | 'NOT LIKE' | 'IN' | 'NOT IN' | 'BETWEEN' | 'NOT BETWEEN' | 'IS' | 'IS NOT' | 'REGEXP' | 'NOT REGEXP' | 'AND' | 'OR' | 'GROUP' | 'CONTAIN' | 'NOT contain' |
|
|
26
|
+
'like' | 'not like' | 'in' | 'not in' | 'between' | 'not between' | 'is' | 'is not' | 'regexp' | 'not regexp' | 'and' | 'or' | 'group' | 'contain' | 'not contain';
|
|
27
27
|
|
|
28
28
|
export interface WhereOptions {
|
|
29
29
|
key: string | null;
|
package/package.json
CHANGED
package/src/builder.js
CHANGED
|
@@ -279,6 +279,18 @@ class Builder {
|
|
|
279
279
|
return res ? `${this._buildFieldKey(condition.key)} ${opt} (${res})` : `${this._buildFieldKey(condition.key)} ${opt} (?)`;
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
+
_buildConditionContain(condition, isNot = false) {
|
|
283
|
+
if (condition.key.indexOf('$') !== -1) {
|
|
284
|
+
let res = this._buildConditionValues(condition.value);
|
|
285
|
+
let sql = res ? `JSON_CONTAINS(${this._buildFieldKey(condition.key)}, JSON_ARRAY(${res}))` :
|
|
286
|
+
`JSON_CONTAINS(${this._buildFieldKey(condition.key)}, JSON_ARRAY(?))`;
|
|
287
|
+
return isNot ? `${sql}=0` : sql;
|
|
288
|
+
}
|
|
289
|
+
let res = this._buildConditionValues(condition.value);
|
|
290
|
+
const opt = isNot ? 'NOT LIKE' : 'LIKE';
|
|
291
|
+
return res ? `${this._buildFieldKey(condition.key)} ${opt} CONCAT('%', ?, '%')` : `${this._buildFieldKey(condition.key)} ${opt} CONCAT('%', ?, '%')`;
|
|
292
|
+
}
|
|
293
|
+
|
|
282
294
|
_buildCondition(conditions, prefix) {
|
|
283
295
|
if (!conditions || !conditions.length) {
|
|
284
296
|
return '';
|
|
@@ -315,6 +327,10 @@ class Builder {
|
|
|
315
327
|
return this._buildConditionIn(c, true);
|
|
316
328
|
} else if (opt === 'group' && Array.isArray(c.value)) {
|
|
317
329
|
return `(${this._buildCondition(c.value, '')})`;
|
|
330
|
+
} else if (opt === 'contain') {
|
|
331
|
+
return this._buildConditionContain(c);
|
|
332
|
+
} else if (opt === 'not contain') {
|
|
333
|
+
return this._buildConditionContain(c, true);
|
|
318
334
|
}
|
|
319
335
|
let res = this._buildConditionValues(c.value);
|
|
320
336
|
if (!is.empty(res)) {
|