@itrocks/mysql 0.0.18 → 0.0.20

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/cjs/mysql.js CHANGED
@@ -134,8 +134,8 @@ class Mysql extends storage_1.DataSource {
134
134
  : property.name;
135
135
  const columnName = depends.columnOf(propertyName);
136
136
  sql.push((columnName.length !== propertyName.length)
137
- ? columnName + ' ' + propertyName
138
- : propertyName);
137
+ ? ('`' + columnName + '` `' + propertyName + '`')
138
+ : ('`' + propertyName + '`'));
139
139
  }
140
140
  return sql.join(', ');
141
141
  }
@@ -244,20 +244,24 @@ class Mysql extends storage_1.DataSource {
244
244
  const propertiesSql = this.propertiesToSqlSelect(type);
245
245
  let sortOption = undefined;
246
246
  for (const option of this.options(options)) {
247
- if ((option instanceof storage_2.Sort) && (option.properties.length)) {
248
- sortOption = option;
247
+ if (option === storage_2.Sort) {
248
+ sortOption = new storage_2.Sort((0, sort_2.sortOf)(type));
249
+ }
250
+ if (option instanceof storage_2.Sort) {
251
+ sortOption = option.properties.length ? option : new storage_2.Sort((0, sort_2.sortOf)(type));
249
252
  }
250
- }
251
- if (!sortOption) {
252
- sortOption = new storage_2.Sort((0, sort_2.sortOf)(type));
253
253
  }
254
254
  Object.setPrototypeOf(search, type.prototype);
255
255
  const sql = this.propertiesToSearchSql(search);
256
256
  const [values] = await this.valuesToDb(search);
257
257
  if (exports.DEBUG)
258
258
  console.log('SELECT ' + propertiesSql + ' FROM `' + depends.storeOf(type) + '`' + sql, '[', values, ']');
259
- const sort = ' ORDER BY '
260
- + sortOption.properties.map(property => '`' + property + '`' + (property instanceof sort_1.Reverse ? ' DESC' : '')).join(', ');
259
+ const sort = sortOption?.properties.length
260
+ ? ' ORDER BY '
261
+ + sortOption.properties
262
+ .map(property => '`' + property + '`' + (property instanceof sort_1.Reverse ? ' DESC' : ''))
263
+ .join(', ')
264
+ : '';
261
265
  const rows = await connection.query('SELECT ' + propertiesSql + ' FROM `' + depends.storeOf(type) + '`' + sql + sort, Object.values(values));
262
266
  return Promise.all(rows.map(row => this.valuesFromDb(row, type)));
263
267
  }
package/esm/mysql.js CHANGED
@@ -129,8 +129,8 @@ export class Mysql extends DataSource {
129
129
  : property.name;
130
130
  const columnName = depends.columnOf(propertyName);
131
131
  sql.push((columnName.length !== propertyName.length)
132
- ? columnName + ' ' + propertyName
133
- : propertyName);
132
+ ? ('`' + columnName + '` `' + propertyName + '`')
133
+ : ('`' + propertyName + '`'));
134
134
  }
135
135
  return sql.join(', ');
136
136
  }
@@ -239,20 +239,24 @@ export class Mysql extends DataSource {
239
239
  const propertiesSql = this.propertiesToSqlSelect(type);
240
240
  let sortOption = undefined;
241
241
  for (const option of this.options(options)) {
242
- if ((option instanceof Sort) && (option.properties.length)) {
243
- sortOption = option;
242
+ if (option === Sort) {
243
+ sortOption = new Sort(sortOf(type));
244
+ }
245
+ if (option instanceof Sort) {
246
+ sortOption = option.properties.length ? option : new Sort(sortOf(type));
244
247
  }
245
- }
246
- if (!sortOption) {
247
- sortOption = new Sort(sortOf(type));
248
248
  }
249
249
  Object.setPrototypeOf(search, type.prototype);
250
250
  const sql = this.propertiesToSearchSql(search);
251
251
  const [values] = await this.valuesToDb(search);
252
252
  if (DEBUG)
253
253
  console.log('SELECT ' + propertiesSql + ' FROM `' + depends.storeOf(type) + '`' + sql, '[', values, ']');
254
- const sort = ' ORDER BY '
255
- + sortOption.properties.map(property => '`' + property + '`' + (property instanceof Reverse ? ' DESC' : '')).join(', ');
254
+ const sort = sortOption?.properties.length
255
+ ? ' ORDER BY '
256
+ + sortOption.properties
257
+ .map(property => '`' + property + '`' + (property instanceof Reverse ? ' DESC' : ''))
258
+ .join(', ')
259
+ : '';
256
260
  const rows = await connection.query('SELECT ' + propertiesSql + ' FROM `' + depends.storeOf(type) + '`' + sql + sort, Object.values(values));
257
261
  return Promise.all(rows.map(row => this.valuesFromDb(row, type)));
258
262
  }
package/package.json CHANGED
@@ -59,5 +59,5 @@
59
59
  "build:esm": "tsc -p tsconfig.esm.json"
60
60
  },
61
61
  "types": "./esm/mysql.d.ts",
62
- "version": "0.0.18"
62
+ "version": "0.0.20"
63
63
  }