@axiosleo/orm-mysql 0.9.7 → 0.9.9

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.7',
12
+ version: '0.9.9',
13
13
  commands_dir: path.join(__dirname, '../commands'),
14
14
  });
15
15
 
package/index.d.ts CHANGED
@@ -101,7 +101,7 @@ export declare class Query {
101
101
 
102
102
  andWhere(key: string | null, opt: OptType, value: ConditionValueType | WhereOptions[]): this;
103
103
 
104
- attr(...attr: Attr[]): this;
104
+ attr(...attr: Attr[] | Attr[][]): this;
105
105
 
106
106
  orderBy(sortField: string, sortOrder: 'asc' | 'desc'): this;
107
107
 
@@ -365,7 +365,7 @@ export declare class MigrationInterface {
365
365
  autoIncrement?: boolean,
366
366
  primaryKey?: boolean,
367
367
  uniqIndex?: boolean,
368
- after?: string
368
+ after?: string,
369
369
  }): void;
370
370
 
371
371
  createIndex(tableName: string, columns: string[], options?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiosleo/orm-mysql",
3
- "version": "0.9.7",
3
+ "version": "0.9.9",
4
4
  "description": "MySQL ORM tool",
5
5
  "keywords": [
6
6
  "mysql",
package/src/builder.js CHANGED
@@ -150,6 +150,7 @@ class Builder {
150
150
  table = `\`${table}\``;
151
151
  }
152
152
  let sql = '';
153
+ join_type = join_type.toLowerCase();
153
154
  switch (join_type) {
154
155
  case 'left':
155
156
  sql = 'LEFT JOIN ';
@@ -370,9 +371,6 @@ class ManageSQLBuilder extends Builder {
370
371
  if (is.empty(options.columns)) {
371
372
  throw new Error('At least one column is required');
372
373
  }
373
- if (!Object.values(options.columns).find(c => c.primaryKey === true)) {
374
- throw new Error('At least one primary key column is required');
375
- }
376
374
  let columns = Object.keys(options.columns).map(name => {
377
375
  return { name, ...options.columns[name] };
378
376
  });
@@ -386,20 +384,9 @@ class ManageSQLBuilder extends Builder {
386
384
  }
387
385
 
388
386
  createColumn(options) {
389
- _validate(options, {
390
- table: 'required|string',
391
- name: 'required|string',
392
- type: 'required|string',
393
- length: 'integer',
394
- unsigned: 'boolean',
395
- allowNull: 'boolean',
396
- default: 'string',
397
- comment: 'string',
398
- autoIncrement: 'boolean',
399
- primaryKey: 'boolean',
400
- uniqIndex: 'boolean',
401
- after: 'string'
402
- });
387
+ if (!options.table) {
388
+ throw new Error('Table name is required');
389
+ }
403
390
  return `ALTER TABLE \`${options.table}\` ADD COLUMN ` + this.renderSingleColumn(options);
404
391
  }
405
392
 
@@ -430,6 +417,8 @@ class ManageSQLBuilder extends Builder {
430
417
  }
431
418
 
432
419
  createForeignKey(options) {
420
+ options.reference.onDelete = options.reference.onDelete ? options.reference.onDelete.toUpperCase() : 'NO ACTION';
421
+ options.reference.onUpdate = options.reference.onUpdate ? options.reference.onUpdate.toUpperCase() : 'NO ACTION';
433
422
  _validate(options, {
434
423
  name: 'required|string',
435
424
  table: 'required|string',
@@ -558,6 +547,8 @@ class ManageSQLBuilder extends Builder {
558
547
  str += '(11)';
559
548
  } else if (type === 'VARCHAR') {
560
549
  str += '(255)';
550
+ } else if (type === 'TINYINT') {
551
+ str += '(4)';
561
552
  }
562
553
  if (options.allowNull === false) {
563
554
  str += ' NOT NULL';
package/src/query.js CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  const { _assign } = require('@axiosleo/cli-tool/src/helper/obj');
4
4
  const { _validate } = require('./utils');
5
- const is = require('@axiosleo/cli-tool/src/helper/is');
6
5
 
7
6
  function joinOn(table, on, options = {}) {
8
7
  let o = _assign({ alias: null, join_type: 'INNER', table, on }, options);
@@ -24,6 +23,7 @@ class Query {
24
23
  conditions: [],
25
24
  orders: [],
26
25
  tables: [],
26
+ attrs: [],
27
27
  operator,
28
28
  data: null,
29
29
  groupField: [],
@@ -124,18 +124,12 @@ class Query {
124
124
  return this;
125
125
  }
126
126
 
127
- attr(...attr) {
128
- if (attr.length === 1 && is.array(attr)) {
129
- this.options.attrs = attr;
130
- return this;
131
- }
132
- if (!attr.length) {
133
- return this;
134
- }
135
- if (!this.options.attrs) {
127
+ attr(...attrs) {
128
+ if (!attrs.length) {
136
129
  this.options.attrs = [];
130
+ return this;
137
131
  }
138
- this.options.attrs.push(...attr);
132
+ this.options.attrs = attrs;
139
133
  return this;
140
134
  }
141
135