@mikro-orm/core 7.2.2-dev.4 → 7.2.2-dev.6
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/EntityManager.js +24 -0
- package/package.json +1 -1
- package/utils/Utils.js +1 -1
package/EntityManager.js
CHANGED
|
@@ -1091,6 +1091,30 @@ export class EntityManager {
|
|
|
1091
1091
|
}
|
|
1092
1092
|
return ret;
|
|
1093
1093
|
}
|
|
1094
|
+
// merge fields are derived from the first row, rows of a different shape need their own statement
|
|
1095
|
+
if (!options.onConflictMergeFields && options.onConflictAction !== 'ignore') {
|
|
1096
|
+
const pks = this.metadata.get(entityName).primaryKeys;
|
|
1097
|
+
const shapes = new Map();
|
|
1098
|
+
data.forEach((row, i) => {
|
|
1099
|
+
// entity instances carry their unset properties as `undefined` keys, while in plain rows those are merged as `null`
|
|
1100
|
+
const shape = Object.keys(row)
|
|
1101
|
+
.filter(key => !pks.includes(key) && !(Utils.isEntity(row) && row[key] === undefined))
|
|
1102
|
+
.sort()
|
|
1103
|
+
.join();
|
|
1104
|
+
const idx = shapes.get(shape) ?? [];
|
|
1105
|
+
shapes.set(shape, idx);
|
|
1106
|
+
idx.push(i);
|
|
1107
|
+
});
|
|
1108
|
+
if (shapes.size > 1) {
|
|
1109
|
+
const ret = [];
|
|
1110
|
+
for (const idx of shapes.values()) {
|
|
1111
|
+
const res = await this.upsertMany(entityName, idx.map(i => data[i]), options);
|
|
1112
|
+
idx.forEach((i, j) => (ret[i] = res[j]));
|
|
1113
|
+
}
|
|
1114
|
+
// rows resolving to the same entity are returned once, as in the single statement path
|
|
1115
|
+
return [...new Set(ret.filter(entity => entity))];
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1094
1118
|
// the rows are replaced with their processed copies below, keep the caller's array intact
|
|
1095
1119
|
data = [...data];
|
|
1096
1120
|
const meta = this.metadata.get(entityName);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.2.2-dev.
|
|
3
|
+
"version": "7.2.2-dev.6",
|
|
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/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.2.2-dev.
|
|
156
|
+
static #ORM_VERSION = '7.2.2-dev.6';
|
|
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}`;
|