typespeed 2.4.7 → 2.4.8

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.
@@ -99,7 +99,10 @@ async function actionExecute(newSql, sqlValues) {
99
99
  async function actionQuery(newSql, sqlValues, dataClassType) {
100
100
  const readConnection = await (0, core_decorator_1.getBean)(data_source_factory_class_1.default).readConnection();
101
101
  const [rows] = await readConnection.query(newSql, sqlValues);
102
- if (rows === null || Object.keys(rows).length === 0 || !dataClassType) {
102
+ if (rows === null || Object.keys(rows).length === 0) {
103
+ return null;
104
+ }
105
+ else if (!dataClassType) {
103
106
  return rows;
104
107
  }
105
108
  const records = [];
@@ -112,7 +115,7 @@ async function actionQuery(newSql, sqlValues, dataClassType) {
112
115
  });
113
116
  records.push(entity);
114
117
  }
115
- return records;
118
+ return Object.keys(records).length === 0 ? null : records;
116
119
  }
117
120
  function convertSQLParams(decoratorSQL, target, propertyKey, args) {
118
121
  const queryValues = [];
@@ -188,7 +191,7 @@ class Model {
188
191
  }
189
192
  else if (typeof limit === 'object') {
190
193
  const total = await actionQuery('SELECT COUNT(*) AS M_COUNTER FROM ' + this.table + ' WHERE ' + sql, values);
191
- if (total === undefined || total[0]['M_COUNTER'] === 0) {
194
+ if (total === null || total[0] === undefined || total[0]['M_COUNTER'] === 0) {
192
195
  return [];
193
196
  }
194
197
  if (limit['pageSize'] !== undefined && limit['pageSize'] < total[0]['M_COUNTER']) {
@@ -220,7 +223,7 @@ class Model {
220
223
  }
221
224
  async find(conditions, sort, fields = '*') {
222
225
  const result = await this.findAll(conditions, sort, fields, 1);
223
- return result.length > 0 ? result[0] : null;
226
+ return result != null && result.length > 0 ? result[0] : null;
224
227
  }
225
228
  async update(conditions, fieldToValues) {
226
229
  const { sql, values } = this.where(conditions);
@@ -238,7 +241,7 @@ class Model {
238
241
  const { sql, values } = this.where(conditions);
239
242
  const newSql = 'SELECT COUNT(*) AS M_COUNTER FROM ' + this.table + ' WHERE ' + sql;
240
243
  const result = await actionQuery(newSql, values);
241
- return result[0]['M_COUNTER'] || 0;
244
+ return result != null && result[0] != undefined ? result[0]['M_COUNTER'] : 0;
242
245
  }
243
246
  async incr(conditions, field, optval = 1) {
244
247
  const { sql, values } = this.where(conditions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typespeed",
3
- "version": "2.4.7",
3
+ "version": "2.4.8",
4
4
  "description": "A new Framework for TypeScript.",
5
5
  "author": "speedphp",
6
6
  "license": "MIT License",
@@ -99,7 +99,9 @@ async function actionExecute(newSql, sqlValues): Promise<ResultSetHeader> {
99
99
  async function actionQuery(newSql, sqlValues, dataClassType?) {
100
100
  const readConnection = await getBean(DataSourceFactory).readConnection();
101
101
  const [rows] = await readConnection.query(newSql, sqlValues);
102
- if (rows === null || Object.keys(rows).length === 0 || !dataClassType) {
102
+ if (rows === null || Object.keys(rows).length === 0){
103
+ return null;
104
+ } else if (!dataClassType) {
103
105
  return rows;
104
106
  }
105
107
  const records = [];
@@ -112,7 +114,7 @@ async function actionQuery(newSql, sqlValues, dataClassType?) {
112
114
  });
113
115
  records.push(entity);
114
116
  }
115
- return records;
117
+ return Object.keys(records).length === 0 ? null : records;
116
118
  }
117
119
 
118
120
  function convertSQLParams(decoratorSQL: string, target: any, propertyKey: string, args: any[]): [string, any[]] {
@@ -192,7 +194,7 @@ class Model {
192
194
  newSql += ' LIMIT ' + limit
193
195
  } else if (typeof limit === 'object') {
194
196
  const total = await actionQuery('SELECT COUNT(*) AS M_COUNTER FROM ' + this.table + ' WHERE ' + sql, values);
195
- if (total === undefined || total[0]['M_COUNTER'] === 0) {
197
+ if (total === null || total[0] === undefined || total[0]['M_COUNTER'] === 0) {
196
198
  return [];
197
199
  }
198
200
  if (limit['pageSize'] !== undefined && limit['pageSize'] < total[0]['M_COUNTER']) {
@@ -226,7 +228,7 @@ class Model {
226
228
 
227
229
  async find<T>(conditions, sort, fields = '*'): Promise<T> {
228
230
  const result = await this.findAll(conditions, sort, fields, 1);
229
- return result.length > 0 ? <T>result[0] : null;
231
+ return result != null && result.length > 0 ? <T>result[0] : null;
230
232
  }
231
233
 
232
234
  async update(conditions, fieldToValues): Promise<number> {
@@ -247,7 +249,7 @@ class Model {
247
249
  const { sql, values } = this.where(conditions);
248
250
  const newSql = 'SELECT COUNT(*) AS M_COUNTER FROM ' + this.table + ' WHERE ' + sql;
249
251
  const result = await actionQuery(newSql, values);
250
- return result[0]['M_COUNTER'] || 0;
252
+ return result != null && result[0] != undefined ? result[0]['M_COUNTER'] : 0;
251
253
  }
252
254
 
253
255
  async incr(conditions, field, optval = 1): Promise<number> {