@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 CHANGED
@@ -9,7 +9,7 @@ const app = new App({
9
9
  name: 'MySQL ORM CLI',
10
10
  desc: 'migrate, model, seed, etc.',
11
11
  bin: 'orm-mysql',
12
- version: '0.9.16',
12
+ version: '0.9.17',
13
13
  commands_dir: path.join(__dirname, '../commands'),
14
14
  });
15
15
 
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 contain' |
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiosleo/orm-mysql",
3
- "version": "0.9.16",
3
+ "version": "0.9.17",
4
4
  "description": "MySQL ORM tool",
5
5
  "keywords": [
6
6
  "mysql",
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('->');