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

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.3',
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.3",
4
4
  "description": "MySQL ORM tool",
5
5
  "keywords": [
6
6
  "mysql",
package/src/operator.js CHANGED
@@ -108,12 +108,21 @@ class QueryOperator extends Query {
108
108
  if (conditions.length === 0) {
109
109
  throw new Error('conditions is required');
110
110
  }
111
+ if (!this.options.tables[0]) {
112
+ throw new Error('table is required');
113
+ }
111
114
  const query = new QueryOperator(this.conn, this.options);
112
- const count = await query.whereConditions(...conditions).count();
115
+ const table = this.options.tables[0].table;
116
+ const alias = this.options.tables[0].alias;
117
+ const count = await query.table(table, alias)
118
+ .whereConditions(...conditions)
119
+ .count();
113
120
  if (count) {
114
- return await query.whereConditions(...conditions).update(data);
121
+ return await query.table(table, alias)
122
+ .whereConditions(...conditions)
123
+ .update(data);
115
124
  }
116
- return await query.insert(data);
125
+ return await query.table(this.options.tables[0]).insert(data);
117
126
  }
118
127
  }
119
128
 
@@ -144,6 +153,13 @@ class QueryHandler {
144
153
  return operator.tables(...tables);
145
154
  }
146
155
 
156
+ /**
157
+ * @deprecated
158
+ * @param {*} tableName
159
+ * @param {*} data
160
+ * @param {*} condition
161
+ * @returns
162
+ */
147
163
  async upsert(tableName, data, condition = {}) {
148
164
  const count = await this.table(tableName).whereObject(condition).count();
149
165
  if (count) {