@axiosleo/orm-mysql 0.11.1 → 0.11.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/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.11.1',
12
+ version: '0.11.2',
13
13
  commands_dir: path.join(__dirname, '../commands'),
14
14
  });
15
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiosleo/orm-mysql",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
4
4
  "description": "MySQL ORM tool",
5
5
  "keywords": [
6
6
  "mysql",
@@ -35,7 +35,7 @@
35
35
  "url": "https://github.com/AxiosLeo/node-orm-mysql"
36
36
  },
37
37
  "devDependencies": {
38
- "@types/node": "^20.11.16",
38
+ "@types/node": "^20.11.26",
39
39
  "chai": "^5.0.3",
40
40
  "eslint": "^8.56.0",
41
41
  "expect.js": "^0.3.1",
package/src/builder.js CHANGED
@@ -298,6 +298,24 @@ class Builder {
298
298
  return null;
299
299
  }
300
300
 
301
+ _buildConditionBetween(condition, isNot = false) {
302
+ if (!Array.isArray(condition.value) || condition.value.length !== 2) {
303
+ throw new Error('Value must be an array with two elements for "BETWEEN" condition');
304
+ }
305
+ this.values.push(condition.value[0] || null);
306
+ this.values.push(condition.value[1] || null);
307
+ if (condition.key.indexOf('->') !== -1) {
308
+ let keys = condition.key.split('->');
309
+ let k = `${this._buildFieldKey(keys[0])}`;
310
+ let sql = `JSON_EXTRACT(${k}, '${keys[1]}') `;
311
+ sql += isNot ? 'NOT BETWEEN' : 'BETWEEN';
312
+ sql += ' ? AND ?';
313
+ return sql;
314
+ }
315
+ const opt = isNot ? 'NOT BETWEEN' : 'BETWEEN';
316
+ return `${this._buildFieldKey(condition.key)} ${opt} ? AND ?`;
317
+ }
318
+
301
319
  _buildConditionIn(condition, isNot = false) {
302
320
  if (Array.isArray(condition.value) && !condition.value.length) {
303
321
  throw new Error('Value must not be empty for "IN" condition');
@@ -369,6 +387,10 @@ class Builder {
369
387
  return this._buildConditionIn(c);
370
388
  } else if (opt === 'not in') {
371
389
  return this._buildConditionIn(c, true);
390
+ } else if (opt === 'between') {
391
+ return this._buildConditionBetween(c);
392
+ } else if (opt === 'not between') {
393
+ return this._buildConditionBetween(c, true);
372
394
  } else if (opt === 'contain') {
373
395
  return this._buildConditionContain(c);
374
396
  } else if (opt === 'not contain') {