@mikro-orm/core 7.2.4-dev.0 → 7.2.4-dev.2
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/unit-of-work/ChangeSetPersister.js +22 -4
- 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.2.4-dev.
|
|
3
|
+
"version": "7.2.4-dev.2",
|
|
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",
|
|
@@ -196,10 +196,17 @@ export class ChangeSetPersister {
|
|
|
196
196
|
}
|
|
197
197
|
async persistManagedEntities(meta, changeSets, options) {
|
|
198
198
|
const size = this.#config.get('batchSize');
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
199
|
+
// a batch checks the version in all rows or none, so references without a loaded version go separately
|
|
200
|
+
const hasVersion = (cs) => cs.entity[meta.versionProperty] != null;
|
|
201
|
+
const groups = meta.ownsVersionProperty()
|
|
202
|
+
? [changeSets.filter(hasVersion), changeSets.filter(cs => !hasVersion(cs))]
|
|
203
|
+
: [changeSets];
|
|
204
|
+
for (const group of groups) {
|
|
205
|
+
for (let i = 0; i < group.length; i += size) {
|
|
206
|
+
const chunk = group.slice(i, i + size);
|
|
207
|
+
await this.persistManagedEntitiesBatch(meta, chunk, options);
|
|
208
|
+
await this.reloadVersionValues(meta, chunk, options);
|
|
209
|
+
}
|
|
203
210
|
}
|
|
204
211
|
}
|
|
205
212
|
checkConcurrencyKeys(meta, changeSet, cond) {
|
|
@@ -223,9 +230,14 @@ export class ChangeSetPersister {
|
|
|
223
230
|
});
|
|
224
231
|
const cond = [];
|
|
225
232
|
const payload = [];
|
|
233
|
+
// like in `updateEntity()`, but the batch needs the version in all rows or none
|
|
234
|
+
const versioned = meta.ownsVersionProperty() && changeSets.every(cs => cs.entity[meta.versionProperty] != null);
|
|
226
235
|
for (const changeSet of changeSets) {
|
|
227
236
|
const where = changeSet.getPrimaryKey(true);
|
|
228
237
|
this.checkConcurrencyKeys(meta, changeSet, where);
|
|
238
|
+
if (versioned) {
|
|
239
|
+
where[meta.versionProperty] = this.#platform.convertVersionValue(changeSet.entity[meta.versionProperty], meta.properties[meta.versionProperty]);
|
|
240
|
+
}
|
|
229
241
|
cond.push(where);
|
|
230
242
|
payload.push(changeSet.payload);
|
|
231
243
|
}
|
|
@@ -235,6 +247,12 @@ export class ChangeSetPersister {
|
|
|
235
247
|
// from those to be able to match them with `getSerializedPrimaryKey()` of the entity
|
|
236
248
|
const pkFields = meta.getPrimaryProps().flatMap(prop => prop.fieldNames);
|
|
237
249
|
res.rows?.forEach(item => map.set(Utils.getPrimaryKeyHash(pkFields.map(field => item[field])), item));
|
|
250
|
+
if ((meta.ownsVersionProperty() || meta.getOwnConcurrencyCheckKeys().length > 0) &&
|
|
251
|
+
res.affectedRows < changeSets.length) {
|
|
252
|
+
// without `returning`, the stale entity can't be identified, so we report the first one
|
|
253
|
+
const failed = changeSets.find(cs => !map.has(helper(cs.entity).getSerializedPrimaryKey())) ?? changeSets[0];
|
|
254
|
+
throw OptimisticLockError.lockFailed(failed.entity);
|
|
255
|
+
}
|
|
238
256
|
for (const changeSet of changeSets) {
|
|
239
257
|
if (res.rows) {
|
|
240
258
|
const row = map.get(helper(changeSet.entity).getSerializedPrimaryKey());
|
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.4-dev.
|
|
156
|
+
static #ORM_VERSION = '7.2.4-dev.2';
|
|
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}`;
|