@axiosleo/orm-mysql 0.9.11-alpha.2 → 0.9.11-alpha.4

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.11-alpha.2',
12
+ version: '0.9.11-alpha.4',
13
13
  commands_dir: path.join(__dirname, '../commands'),
14
14
  });
15
15
 
package/index.d.ts CHANGED
@@ -21,9 +21,9 @@ export type Clients = {
21
21
 
22
22
  export type ConditionValueType = null | string | number | boolean | Date | Array<string | number | boolean | Date> | Query;
23
23
 
24
- export type OptType = '=' | '!=' | '>' | '<' | '>=' | '<=' | 'LIKE'
25
- | 'NOT LIKE' | 'IN' | 'NOT IN' | 'BETWEEN' | 'NOT BETWEEN' | 'IS' | 'IS NOT' | 'REGEXP' | 'NOT REGEXP'
26
- | 'AND' | 'OR' | 'GROUP' | 'like' | 'not like' | 'in' | 'not in' | 'between' | 'not between' | 'is' | 'is not' | 'regexp' | 'not regexp' | 'group';
24
+ export type OptType = '=' | '!=' | '>' | '<' | '>=' | '<=' |
25
+ 'LIKE' | 'NOT LIKE' | 'IN' | 'NOT IN' | 'BETWEEN' | 'NOT BETWEEN' | 'IS' | 'IS NOT' | 'REGEXP' | 'NOT REGEXP' | 'AND' | 'OR' | 'GROUP' |
26
+ 'like' | 'not like' | 'in' | 'not in' | 'between' | 'not between' | 'is' | 'is not' | 'regexp' | 'not regexp' | 'and' | 'or' | 'group';
27
27
 
28
28
  export interface WhereOptions {
29
29
  key: string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiosleo/orm-mysql",
3
- "version": "0.9.11-alpha.2",
3
+ "version": "0.9.11-alpha.4",
4
4
  "description": "MySQL ORM tool",
5
5
  "keywords": [
6
6
  "mysql",
package/src/operator.js CHANGED
@@ -1,9 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ const os = require('os');
3
4
  const { Builder } = require('./builder');
4
5
  const Query = require('./query');
5
6
  const Hook = require('./hook');
6
7
  const { _query } = require('./core');
8
+ const { printer } = require('@axiosleo/cli-tool');
7
9
 
8
10
  class QueryOperator extends Query {
9
11
  /**
@@ -56,6 +58,18 @@ class QueryOperator extends Query {
56
58
  }
57
59
  Hook.listen({ label: 'post', table: from, opt: this.options.operator }, this.options, res);
58
60
  } catch (err) {
61
+ const e = new Error();
62
+ let f = e.stack.split(os.EOL).find(s =>
63
+ !s.startsWith('Error') &&
64
+ s.indexOf('QueryOperator') < 0 &&
65
+ s.indexOf('node:internal') < 0
66
+ );
67
+ if (f) {
68
+ printer.println();
69
+ printer.print('[MySQL] error : '.data).print(f.trim().warning).println();
70
+ printer.print('[MySQL] message: '.data).print(err.message.error).println();
71
+ printer.print('[MySQL] query : '.data).print(err.sql).println().println();
72
+ }
59
73
  Hook.listen({ label: 'post', table: from, opt: this.options.operator }, this.options, err);
60
74
  throw err;
61
75
  }
@@ -108,10 +122,19 @@ class QueryOperator extends Query {
108
122
  if (conditions.length === 0) {
109
123
  throw new Error('conditions is required');
110
124
  }
125
+ if (!this.options.tables[0]) {
126
+ throw new Error('table is required');
127
+ }
111
128
  const query = new QueryOperator(this.conn, this.options);
112
- const count = await query.whereConditions(...conditions).count();
129
+ const table = this.options.tables[0].table;
130
+ const alias = this.options.tables[0].alias;
131
+ const count = await query.table(table, alias)
132
+ .whereConditions(...conditions)
133
+ .count();
113
134
  if (count) {
114
- return await query.whereConditions(...conditions).update(data);
135
+ return await query
136
+ .whereConditions(...conditions)
137
+ .update(data);
115
138
  }
116
139
  return await query.insert(data);
117
140
  }
@@ -144,6 +167,13 @@ class QueryHandler {
144
167
  return operator.tables(...tables);
145
168
  }
146
169
 
170
+ /**
171
+ * @deprecated
172
+ * @param {*} tableName
173
+ * @param {*} data
174
+ * @param {*} condition
175
+ * @returns
176
+ */
147
177
  async upsert(tableName, data, condition = {}) {
148
178
  const count = await this.table(tableName).whereObject(condition).count();
149
179
  if (count) {