@axiosleo/orm-mysql 0.9.4 → 0.9.5

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.4',
12
+ version: '0.9.5',
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.9.4",
3
+ "version": "0.9.5",
4
4
  "description": "MySQL ORM tool",
5
5
  "keywords": [
6
6
  "mysql",
package/src/builder.js CHANGED
@@ -37,6 +37,7 @@ class Builder {
37
37
  if (attr instanceof Function) {
38
38
  const query = attr();
39
39
  const builder = new Builder(query.options);
40
+ this.values = this.values.concat(builder.values);
40
41
  let s = `(${builder.sql})`;
41
42
  if (query.alias) {
42
43
  return query.alias.indexOf(' ') > -1 ? s + ' ' + this._buildFieldKey(query.alias)
@@ -48,9 +49,9 @@ class Builder {
48
49
  });
49
50
  emit(tmp, `SELECT ${attrs.length ? attrs.map((a) => this._buildFieldKey(a)).join(',') : '*'} FROM ${this._buildTables(options.tables)}`);
50
51
  emit(tmp, this._buildJoins(options.joins));
51
- emit(tmp, this._buildContidion(options.conditions));
52
+ emit(tmp, this._buildCondition(options.conditions));
52
53
  emit(tmp, this._buildOrders(options.orders));
53
- emit(tmp, this._buldPagenation(options.pageLimit, options.pageOffset));
54
+ emit(tmp, this._buildPagination(options.pageLimit, options.pageOffset));
54
55
  if (options.having && options.having.length && !options.groupField.length) {
55
56
  throw new Error('having is not allowed without "GROUP BY"');
56
57
  }
@@ -76,7 +77,7 @@ class Builder {
76
77
  if (!options.conditions.length) {
77
78
  throw new Error('At least one condition is required for update operation');
78
79
  }
79
- emit(tmp, this._buildContidion(options.conditions));
80
+ emit(tmp, this._buildCondition(options.conditions));
80
81
  sql = tmp.join(' ');
81
82
  break;
82
83
  }
@@ -85,14 +86,14 @@ class Builder {
85
86
  if (!options.conditions.length) {
86
87
  throw new Error('At least one where condition is required for delete operation');
87
88
  }
88
- emit(tmp, this._buildContidion(options.conditions));
89
+ emit(tmp, this._buildCondition(options.conditions));
89
90
  sql = tmp.join(' ');
90
91
  break;
91
92
  }
92
93
  case 'count': {
93
94
  emit(tmp, `SELECT COUNT(*) AS count FROM ${this._buildTables(options.tables)}`);
94
95
  emit(tmp, this._buildJoins(options.joins));
95
- emit(tmp, this._buildContidion(options.conditions));
96
+ emit(tmp, this._buildCondition(options.conditions));
96
97
  if (options.having && options.having.length && !options.groupField.length) {
97
98
  throw new Error('having is not allowed without "GROUP BY"');
98
99
  }
@@ -122,7 +123,7 @@ class Builder {
122
123
  if (!having || !having.length) {
123
124
  return '';
124
125
  }
125
- return this._buildContidion(having, 'HAVING ');
126
+ return this._buildCondition(having, 'HAVING ');
126
127
  }
127
128
 
128
129
  _buildJoins(joins = []) {
@@ -130,7 +131,7 @@ class Builder {
130
131
  let { table, alias, self_column, foreign_column, join_type } = j;
131
132
  if (table instanceof Query) {
132
133
  if (!alias) {
133
- throw new Error('Alias is required for subquery');
134
+ throw new Error('Alias is required for subQuery');
134
135
  }
135
136
  const builder = new Builder(table.options);
136
137
  this.values = this.values.concat(builder.values);
@@ -186,7 +187,7 @@ class Builder {
186
187
  }).join(' , ');
187
188
  }
188
189
 
189
- _buldPagenation(limit, offset) {
190
+ _buildPagination(limit, offset) {
190
191
  let sql = '';
191
192
  if (limit) {
192
193
  sql += ` LIMIT ${limit}`;
@@ -227,7 +228,7 @@ class Builder {
227
228
  return null;
228
229
  }
229
230
 
230
- _buildContidionIn(condition, isNot = false) {
231
+ _buildConditionIn(condition, isNot = false) {
231
232
  if (Array.isArray(condition.value) && !condition.value.length) {
232
233
  throw new Error('Value must not be empty for "IN" condition');
233
234
  } else if (!Array.isArray(condition.value) && !(condition.value instanceof Query)) {
@@ -244,7 +245,7 @@ class Builder {
244
245
  return res ? `${this._buildFieldKey(condition.key)} ${opt} (${res})` : `${this._buildFieldKey(condition.key)} ${opt} (?)`;
245
246
  }
246
247
 
247
- _buildContidion(conditions, prefix) {
248
+ _buildCondition(conditions, prefix) {
248
249
  if (!conditions || !conditions.length) {
249
250
  return '';
250
251
  }
@@ -265,7 +266,7 @@ class Builder {
265
266
  }
266
267
  if (c.key && c.key.indexOf('->') !== -1) {
267
268
  const keys = c.key.split('->');
268
- return this._buildContidion([
269
+ return this._buildCondition([
269
270
  {
270
271
  key: `JSON_EXTRACT(${this._buildFieldKey(keys[0])}, '${keys[1]}')`,
271
272
  opt: c.opt,
@@ -275,11 +276,11 @@ class Builder {
275
276
  }
276
277
  const opt = c.opt.toLowerCase();
277
278
  if (opt === 'in') {
278
- return this._buildContidionIn(c);
279
+ return this._buildConditionIn(c);
279
280
  } else if (opt === 'not in') {
280
- return this._buildContidionIn(c, true);
281
+ return this._buildConditionIn(c, true);
281
282
  } else if (opt === 'group' && Array.isArray(c.value)) {
282
- return `(${this._buildContidion(c.value, '')})`;
283
+ return `(${this._buildCondition(c.value, '')})`;
283
284
  }
284
285
  let res = this._buildConditionValues(c.value);
285
286
  if (!is.empty(res)) {