@axiosleo/orm-mysql 0.9.10 → 0.9.11-alpha.1

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/.eslintrc CHANGED
@@ -7,22 +7,10 @@
7
7
  "SwitchCase": 1
8
8
  }
9
9
  ],
10
- "quotes": [
11
- 2,
12
- "single"
13
- ],
14
- "linebreak-style": [
15
- 0,
16
- "unix"
17
- ],
18
- "semi": [
19
- 2,
20
- "always"
21
- ],
22
- "strict": [
23
- 2,
24
- "global"
25
- ],
10
+ "quotes": [2, "single"],
11
+ "linebreak-style": [0, "unix"],
12
+ "semi": [2, "always"],
13
+ "strict": [2, "global"],
26
14
  "curly": 2,
27
15
  "eqeqeq": 2,
28
16
  "no-eval": 2,
@@ -65,16 +53,9 @@
65
53
  "afterColon": true
66
54
  }
67
55
  ],
68
- "eol-last": [
69
- 2,
70
- "always"
71
- ],
72
- "no-inner-declarations": [
73
- 1
74
- ],
75
- "no-case-declarations": [
76
- 1
77
- ],
56
+ "eol-last": [2, "always"],
57
+ "no-inner-declarations": [1],
58
+ "no-case-declarations": [1],
78
59
  "no-multiple-empty-lines": [
79
60
  2,
80
61
  {
@@ -82,10 +63,7 @@
82
63
  "maxBOF": 1
83
64
  }
84
65
  ],
85
- "space-in-parens": [
86
- 2,
87
- "never"
88
- ],
66
+ "space-in-parens": [2, "never"],
89
67
  "no-multi-spaces": [
90
68
  2,
91
69
  {
@@ -107,9 +85,9 @@
107
85
  "afterEach": true
108
86
  },
109
87
  "parserOptions": {
110
- "ecmaVersion": 2018,
88
+ "ecmaVersion": 2020,
111
89
  "sourceType": "script",
112
90
  "ecmaFeatures": {}
113
91
  },
114
92
  "extends": "eslint:recommended"
115
- }
93
+ }
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.10',
12
+ version: '0.9.11-alpha.1',
13
13
  commands_dir: path.join(__dirname, '../commands'),
14
14
  });
15
15
 
package/index.d.ts CHANGED
@@ -114,7 +114,7 @@ export declare class Query {
114
114
 
115
115
  andWhere(key: string | null, opt: OptType, value: ConditionValueType | WhereOptions[]): this;
116
116
 
117
- attr(...attr: Attr[] | Attr[][]): this;
117
+ attr(...attr: Attr[]): this;
118
118
 
119
119
  orderBy(sortField: string, sortOrder: 'asc' | 'desc'): this;
120
120
 
@@ -147,14 +147,18 @@ export declare class QueryOperator extends Query {
147
147
 
148
148
  exec(): Promise<QueryResult>;
149
149
 
150
- select<T>(): Promise<T[]>;
150
+ select<T>(...attrs: string[]): Promise<T[]>;
151
151
 
152
152
  find<T>(): Promise<T>;
153
153
 
154
154
  update(data?: any): Promise<MySQLQueryResult>;
155
155
 
156
+ update<T extends Object>(data?: T): Promise<MySQLQueryResult>;
157
+
156
158
  insert(data?: any): Promise<MySQLQueryResult>;
157
159
 
160
+ insert<T extends Object>(data?: T): Promise<MySQLQueryResult>;
161
+
158
162
  count(): Promise<number>;
159
163
 
160
164
  /**
@@ -163,6 +167,8 @@ export declare class QueryOperator extends Query {
163
167
  * @param index_field_name default is 'id'
164
168
  */
165
169
  delete(id?: number, index_field_name?: string): Promise<MySQLQueryResult>;
170
+
171
+ upsertRow<T extends Object>(data: T, ...conditions: WhereOptions[]): Promise<MySQLQueryResult>;
166
172
  }
167
173
 
168
174
  export declare class QueryHandler {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiosleo/orm-mysql",
3
- "version": "0.9.10",
3
+ "version": "0.9.11-alpha.1",
4
4
  "description": "MySQL ORM tool",
5
5
  "keywords": [
6
6
  "mysql",
package/src/operator.js CHANGED
@@ -62,7 +62,10 @@ class QueryOperator extends Query {
62
62
  return res;
63
63
  }
64
64
 
65
- async select() {
65
+ async select(...attrs) {
66
+ if (attrs.length > 0) {
67
+ this.options.attrs = attrs;
68
+ }
66
69
  this.options.operator = 'select';
67
70
  return await this.exec();
68
71
  }
@@ -82,7 +85,7 @@ class QueryOperator extends Query {
82
85
 
83
86
  async insert(data) {
84
87
  this.options.operator = 'insert';
85
- if (data) {
88
+ if (typeof data !== 'undefined') {
86
89
  this.set(data);
87
90
  }
88
91
  return await this.exec();
@@ -100,6 +103,15 @@ class QueryOperator extends Query {
100
103
  this.options.operator = 'delete';
101
104
  return await this.exec();
102
105
  }
106
+
107
+ async upsertRow(data, condition = []) {
108
+ const query = new QueryOperator(this.conn, this.options);
109
+ const count = await query.whereConditions(...condition).count();
110
+ if (count) {
111
+ return await query.whereConditions(...condition).update(data);
112
+ }
113
+ return await query.insert(data);
114
+ }
103
115
  }
104
116
 
105
117
  class QueryHandler {
package/src/query.js CHANGED
@@ -165,7 +165,7 @@ class Query {
165
165
  }
166
166
 
167
167
  groupBy(...groupField) {
168
- this.options.groupField.push(...groupField);
168
+ this.options.groupField = groupField;
169
169
  return this;
170
170
  }
171
171