@mikro-orm/core 7.3.0-dev.11 → 7.3.0-dev.13
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/package.json +1 -1
- package/types/DecimalType.js +34 -1
- package/utils/Utils.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.3.0-dev.
|
|
3
|
+
"version": "7.3.0-dev.13",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
package/types/DecimalType.js
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
import { Type } from './Type.js';
|
|
2
|
+
/** Scales a plain decimal string to an integer rounded half away from zero at `scale`, like the DB does. */
|
|
3
|
+
function toScaledInteger(value, scale) {
|
|
4
|
+
if (typeof value !== 'string') {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
const negative = value.startsWith('-');
|
|
8
|
+
const [int, fraction = ''] = (negative ? value.slice(1) : value).split('.');
|
|
9
|
+
const digits = int + fraction;
|
|
10
|
+
for (let i = 0; i < digits.length; i++) {
|
|
11
|
+
const code = digits.charCodeAt(i);
|
|
12
|
+
if (code < 48 || code > 57) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
let scaled = BigInt('0' + int + fraction.slice(0, scale).padEnd(scale, '0'));
|
|
17
|
+
if (fraction.charCodeAt(scale) >= 53) {
|
|
18
|
+
scaled++;
|
|
19
|
+
}
|
|
20
|
+
return negative ? -scaled : scaled;
|
|
21
|
+
}
|
|
2
22
|
/**
|
|
3
23
|
* Type that maps an SQL DECIMAL to a JS string or number.
|
|
4
24
|
*/
|
|
@@ -16,7 +36,20 @@ export class DecimalType extends Type {
|
|
|
16
36
|
return String(value);
|
|
17
37
|
}
|
|
18
38
|
compareValues(a, b) {
|
|
19
|
-
|
|
39
|
+
if (a === b) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
const scale = this.prop?.scale;
|
|
43
|
+
if (this.platform.formatDecimal(a, scale) !== this.platform.formatDecimal(b, scale)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
// doubles are exact only up to 15 significant digits, so only higher precision strings can differ past the numeric check
|
|
47
|
+
if ((this.prop?.precision ?? 0) <= 15 || this.compareAsType() !== 'string') {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
const scaledA = toScaledInteger(a, scale ?? 0);
|
|
51
|
+
const scaledB = toScaledInteger(b, scale ?? 0);
|
|
52
|
+
return scaledA == null || scaledB == null || scaledA === scaledB;
|
|
20
53
|
}
|
|
21
54
|
getColumnType(prop, platform) {
|
|
22
55
|
return platform.getDecimalTypeDeclarationSQL(prop);
|
package/utils/Utils.js
CHANGED
|
@@ -153,7 +153,7 @@ export function parseJsonSafe(value) {
|
|
|
153
153
|
/** Collection of general-purpose utility methods used throughout the ORM. */
|
|
154
154
|
export class Utils {
|
|
155
155
|
static PK_SEPARATOR = '~~~';
|
|
156
|
-
static #ORM_VERSION = '7.3.0-dev.
|
|
156
|
+
static #ORM_VERSION = '7.3.0-dev.13';
|
|
157
157
|
/** Default session variable name backing an RLS filter argument (`current_setting('mikro.<filter>.<arg>')`). */
|
|
158
158
|
static getRlsSettingName(filterName, argName) {
|
|
159
159
|
return `mikro.${filterName}.${argName}`;
|