leoric 2.0.0 → 2.0.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/History.md +9 -0
- package/package.json +1 -1
- package/src/collection.js +11 -2
- package/src/contants.js +13 -0
- package/src/spell.js +1 -8
package/History.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
2.0.1 / 2022-01-05
|
|
2
|
+
==================
|
|
3
|
+
|
|
4
|
+
## What's Changed
|
|
5
|
+
* fix: format numeric result by @JimmyDaddy in https://github.com/cyjake/leoric/pull/253
|
|
6
|
+
* fix: should still return number if value is '0.000' by @cyjake in https://github.com/cyjake/leoric/pull/254
|
|
7
|
+
|
|
8
|
+
**Full Changelog**: https://github.com/cyjake/leoric/compare/v1.15.1...v2.0.1
|
|
9
|
+
|
|
1
10
|
2.0.0 / 2021-12-28
|
|
2
11
|
==================
|
|
3
12
|
|
package/package.json
CHANGED
package/src/collection.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { AGGREGATOR_MAP } = require('./contants');
|
|
4
|
+
|
|
5
|
+
const AGGREGATORS = Object.values(AGGREGATOR_MAP);
|
|
3
6
|
/**
|
|
4
7
|
* An extended Array to represent collections of models.
|
|
5
8
|
*/
|
|
@@ -87,8 +90,14 @@ function dispatch(spell, rows, fields) {
|
|
|
87
90
|
const { type, value, args } = columns[0];
|
|
88
91
|
if (type === 'alias' && args && args[0].type === 'func') {
|
|
89
92
|
const row = rows[0];
|
|
90
|
-
const
|
|
91
|
-
|
|
93
|
+
const record = row && (row[''] || row[table]);
|
|
94
|
+
const result = record && record[value];
|
|
95
|
+
// see https://www.w3schools.com/mysql/mysql_ref_functions.asp
|
|
96
|
+
if (AGGREGATORS.includes(args[0].name)) {
|
|
97
|
+
const num = Number(result);
|
|
98
|
+
return isNaN(num) ? result : num;
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
92
101
|
}
|
|
93
102
|
}
|
|
94
103
|
|
package/src/contants.js
ADDED
package/src/spell.js
CHANGED
|
@@ -11,6 +11,7 @@ const { isPlainObject } = require('./utils');
|
|
|
11
11
|
const { IndexHint, INDEX_HINT_TYPE, Hint } = require('./hint');
|
|
12
12
|
const { parseObject } = require('./query_object');
|
|
13
13
|
const Raw = require('./raw');
|
|
14
|
+
const { AGGREGATOR_MAP } = require('./contants');
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Parse condition expressions
|
|
@@ -903,14 +904,6 @@ class Spell {
|
|
|
903
904
|
}
|
|
904
905
|
}
|
|
905
906
|
|
|
906
|
-
const AGGREGATOR_MAP = {
|
|
907
|
-
count: 'count',
|
|
908
|
-
average: 'avg',
|
|
909
|
-
minimum: 'min',
|
|
910
|
-
maximum: 'max',
|
|
911
|
-
sum: 'sum'
|
|
912
|
-
};
|
|
913
|
-
|
|
914
907
|
for (const aggregator in AGGREGATOR_MAP) {
|
|
915
908
|
const func = AGGREGATOR_MAP[aggregator];
|
|
916
909
|
Object.defineProperty(Spell.prototype, `$${aggregator}`, {
|