@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 +1 -1
- package/index.d.ts +3 -3
- package/package.json +1 -1
- package/src/operator.js +19 -3
package/bin/orm-mysql.js
CHANGED
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 = '=' | '!=' | '>' | '<' | '>=' | '<=' |
|
|
25
|
-
| 'NOT LIKE' | 'IN' | 'NOT IN' | 'BETWEEN' | 'NOT BETWEEN' | 'IS' | 'IS NOT' | 'REGEXP' | 'NOT REGEXP'
|
|
26
|
-
|
|
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
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
|
|
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.
|
|
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) {
|