@axiosleo/orm-mysql 0.9.12 → 0.9.13

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/README.md CHANGED
@@ -104,6 +104,13 @@ async function insertExample() {
104
104
  name: "Joe",
105
105
  age: 18,
106
106
  });
107
+
108
+ // The insert operation will be changed to the update operation if the uuid already exists
109
+ row = await query.keys('uuid').insert({
110
+ uuid: 'uuid-string',
111
+ name: "Joe",
112
+ age: 18,
113
+ })
107
114
  }
108
115
 
109
116
  async function updateExample() {
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.12',
12
+ version: '0.9.13',
13
13
  commands_dir: path.join(__dirname, '../commands'),
14
14
  });
15
15
 
package/index.d.ts CHANGED
@@ -81,6 +81,7 @@ export type QueryOperatorOptions = QueryOperatorBaseOptions & {
81
81
  having: WhereOptions[];
82
82
  suffix?: string | null;
83
83
  transaction: boolean;
84
+ explain?: boolean;
84
85
  }
85
86
 
86
87
  export declare class Query {
@@ -133,6 +134,23 @@ export declare class Query {
133
134
 
134
135
  export type QueryResult = any | undefined | RowDataPacket[] | RowDataPacket | MySQLQueryResult;
135
136
 
137
+ export type ExplainResult = {
138
+ select_type: 'PRIMARY' | 'DERIVED';
139
+ table: string;
140
+ partitions: string | null;
141
+ type: string | 'ALL' | 'eq_ref';
142
+ possible_keys: null | 'PRIMARY';
143
+ key: null | string;
144
+ key_len: null | number;
145
+ ref: null | string;
146
+ rows: number;
147
+ filtered: number;
148
+ Extra: null | string | 'Using filesort';
149
+
150
+ id?: number;
151
+ [property: string]: any;
152
+ };
153
+
136
154
  export declare class QueryOperator extends Query {
137
155
  conn: Connection | Pool;
138
156
  options: QueryOperatorOptions
@@ -143,6 +161,8 @@ export declare class QueryOperator extends Query {
143
161
 
144
162
  exec(): Promise<QueryResult>;
145
163
 
164
+ explain(operator: OperatorType): Promise<ExplainResult[]>;
165
+
146
166
  select<T>(...attrs: string[]): Promise<T[]>;
147
167
 
148
168
  find<T>(): Promise<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiosleo/orm-mysql",
3
- "version": "0.9.12",
3
+ "version": "0.9.13",
4
4
  "description": "MySQL ORM tool",
5
5
  "keywords": [
6
6
  "mysql",
package/src/builder.js CHANGED
@@ -120,6 +120,10 @@ class Builder {
120
120
  throw new Error('Invalid operator: ' + options.operator);
121
121
  }
122
122
 
123
+ if (options.explain) {
124
+ sql = 'EXPLAIN ' + sql;
125
+ }
126
+
123
127
  this.sql = sql;
124
128
  }
125
129
 
@@ -147,8 +151,10 @@ class Builder {
147
151
  const builder = new Builder(table.options);
148
152
  this.values = this.values.concat(builder.values);
149
153
  table = `(${builder.sql})`;
150
- }
151
- if (alias) {
154
+ if (alias) {
155
+ table = `${table} AS \`${alias}\``;
156
+ }
157
+ } else if (alias) {
152
158
  table = `\`${table}\` AS \`${alias}\``;
153
159
  } else {
154
160
  table = `\`${table}\``;
package/src/operator.js CHANGED
@@ -32,6 +32,12 @@ class QueryOperator extends Query {
32
32
  return new Builder(this.options);
33
33
  }
34
34
 
35
+ async explain(operator) {
36
+ this.options.operator = operator;
37
+ this.options.explain = true;
38
+ return await this.exec();
39
+ }
40
+
35
41
  async exec() {
36
42
  if (!this.options.operator) {
37
43
  throw new Error('Invalid operator: ' + this.options.operator);
package/src/query.js CHANGED
@@ -33,6 +33,7 @@ class Query {
33
33
  suffix: null,
34
34
  transaction: false,
35
35
  keys: null,
36
+ explain: false,
36
37
  };
37
38
  this.alias = alias || null;
38
39
  }