@axiosleo/orm-mysql 0.11.0 → 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.
@@ -0,0 +1,5 @@
1
+ {
2
+ "cSpell.words": [
3
+ "fulltext"
4
+ ]
5
+ }
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.0',
12
+ version: '0.11.2',
13
13
  commands_dir: path.join(__dirname, '../commands'),
14
14
  });
15
15
 
package/index.d.ts CHANGED
@@ -223,42 +223,42 @@ export declare class QueryOperator extends Query {
223
223
  /**
224
224
  * @deprecated will deprecated on v1.0+ version
225
225
  */
226
- buildSql(operator: OperatorType): { sql: string, values: any[] };
226
+ buildSql(operator: OperatorType): Builder;
227
227
 
228
228
  exec(): Promise<QueryResult>;
229
229
 
230
230
  explain(operator: OperatorType): Promise<ExplainResult[]>;
231
231
 
232
- select<T>(...attrs: string[]): Promise<T[]>;
232
+ select<T>(...attrs: string[]): Promise<T[] | Builder>;
233
233
 
234
- find<T>(): Promise<T>;
234
+ find<T>(): Promise<T | Builder>;
235
235
 
236
- count(): Promise<number>;
236
+ count(): Promise<number | Builder>;
237
237
 
238
238
  /**
239
239
  * increment a column value
240
240
  * @param attr
241
241
  * @param increment default is 1
242
242
  */
243
- incrBy(attr: string, increment?: string | number | ((number: number) => number)): Promise<MySQLQueryResult>;
243
+ incrBy(attr: string, increment?: string | number | ((number: number) => number)): Promise<MySQLQueryResult | Builder>;
244
244
 
245
- delete(id?: number, index_field_name?: string): Promise<MySQLQueryResult>;
245
+ delete(id?: number, index_field_name?: string): Promise<MySQLQueryResult | Builder>;
246
246
 
247
- update(row?: any): Promise<MySQLQueryResult>;
247
+ update(row?: any): Promise<MySQLQueryResult | Builder>;
248
248
 
249
- update<T extends Object>(row?: T): Promise<MySQLQueryResult>;
249
+ update<T extends Object>(row?: T): Promise<MySQLQueryResult | Builder>;
250
250
 
251
- insert(row?: any): Promise<MySQLQueryResult>;
251
+ insert(row?: any): Promise<MySQLQueryResult | Builder>;
252
252
 
253
- insert<T extends Object>(row?: T): Promise<MySQLQueryResult>;
253
+ insert<T extends Object>(row?: T): Promise<MySQLQueryResult | Builder>;
254
254
 
255
- insertAll(rows: any[]): Promise<MySQLQueryResult[]>;
255
+ insertAll(rows: any[]): Promise<MySQLQueryResult[] | Builder>;
256
256
 
257
- insertAll<T extends Object>(rows: T[]): Promise<MySQLQueryResult[]>;
257
+ insertAll<T extends Object>(rows: T[]): Promise<MySQLQueryResult[] | Builder>;
258
258
 
259
- upsertRow(row: any, condition: QueryCondition): Promise<MySQLQueryResult>;
259
+ upsertRow(row: any, condition: QueryCondition): Promise<MySQLQueryResult | Builder>;
260
260
 
261
- upsertRow<T extends Object>(row: T, ...conditions: WhereItem[]): Promise<MySQLQueryResult>;
261
+ upsertRow<T extends Object>(row: T, ...conditions: WhereItem[]): Promise<MySQLQueryResult | Builder>;
262
262
 
263
263
  notExec(): this;
264
264
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiosleo/orm-mysql",
3
- "version": "0.11.0",
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') {
package/src/operator.js CHANGED
@@ -41,6 +41,7 @@ class QueryOperator extends Query {
41
41
  async explain(operator) {
42
42
  this.options.operator = operator;
43
43
  this.options.explain = true;
44
+ this.options.notExec = false;
44
45
  return await this.exec();
45
46
  }
46
47