@itrocks/mysql 0.0.18 → 0.0.19
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 +11 -7
- package/esm/mysql.js +11 -7
- package/package.json +1 -1
package/cjs/mysql.js
CHANGED
|
@@ -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 (
|
|
248
|
-
sortOption =
|
|
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 =
|
|
260
|
-
|
|
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
|
@@ -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 (
|
|
243
|
-
sortOption =
|
|
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 =
|
|
255
|
-
|
|
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