@mikro-orm/mysql 7.3.0-dev.16 → 7.3.0-dev.18

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.
@@ -155,6 +155,9 @@ export class MySqlConnection extends AbstractSqlConnection {
155
155
  }
156
156
  async commit(ctx, eventBroadcaster) {
157
157
  if (!ctx.isRolledBack && 'savepointName' in ctx) {
158
+ if ('failedSavepointRollback' in ctx) {
159
+ throw ctx.failedSavepointRollback;
160
+ }
158
161
  try {
159
162
  await ctx.releaseSavepoint(ctx.savepointName).execute();
160
163
  }
package/MySqlDriver.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Configuration, Constructor, EntityDictionary, EntityName, FilterQuery, NativeInsertUpdateManyOptions, QueryResult, UpsertManyOptions } from '@mikro-orm/core';
1
+ import { type Configuration, type Constructor, type EntityDictionary, type EntityName, type FilterQuery, type NativeInsertUpdateManyOptions, type QueryResult, type UpsertManyOptions } from '@mikro-orm/core';
2
2
  import { AbstractSqlDriver } from '@mikro-orm/sql';
3
3
  import { MySqlConnection } from './MySqlConnection.js';
4
4
  import { MySqlMikroORM } from './MySqlMikroORM.js';
package/MySqlDriver.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { isRaw, } from '@mikro-orm/core';
1
2
  import { AbstractSqlDriver, Utils } from '@mikro-orm/sql';
2
3
  import { MySqlConnection } from './MySqlConnection.js';
3
4
  import { MySqlMikroORM } from './MySqlMikroORM.js';
@@ -19,13 +20,29 @@ export class MySqlDriver extends AbstractSqlDriver {
19
20
  }
20
21
  async nativeInsertMany(entityName, data, options = {}) {
21
22
  options.processCollections ??= true;
22
- const res = await super.nativeInsertMany(entityName, data, options);
23
23
  const meta = this.metadata.get(entityName);
24
+ const pk = meta.primaryKeys[0];
25
+ // mysql continues auto_increment from an explicit id, so a generated row after one starts a new insert
26
+ const split = data.findIndex((item, idx) => idx > 0 && item[pk] == null && data[idx - 1][pk] != null);
27
+ if (split > 0) {
28
+ const res = await this.nativeInsertMany(entityName, data.slice(0, split), options);
29
+ const rest = await this.nativeInsertMany(entityName, data.slice(split), options);
30
+ res.rows.push(...rest.rows);
31
+ res.affectedRows += rest.affectedRows;
32
+ res.insertedIds = res.insertedIds && rest.insertedIds ? [...res.insertedIds, ...rest.insertedIds] : undefined;
33
+ return res;
34
+ }
35
+ const res = await super.nativeInsertMany(entityName, data, options);
24
36
  const pks = this.getPrimaryKeyFields(meta);
25
37
  const ctx = options.ctx;
26
38
  const autoIncrementIncrement = await this.getAutoIncrementIncrement(ctx);
27
- data.forEach((item, idx) => (res.rows[idx] = { [pks[0]]: item[pks[0]] ?? res.insertId + idx * autoIncrementIncrement }));
39
+ data.forEach((item, idx) => (res.rows[idx] = { [pks[0]]: item[pk] ?? res.insertId + idx * autoIncrementIncrement }));
28
40
  res.row = res.rows[0];
41
+ const ids = res.rows.map(row => row[pks[0]]);
42
+ // without `returning` the value of a raw pk expression is never known
43
+ if (pks.length === 1 && !ids.some(isRaw)) {
44
+ res.insertedIds = ids;
45
+ }
29
46
  return res;
30
47
  }
31
48
  async nativeUpdateMany(entityName, where, data, options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/mysql",
3
- "version": "7.3.0-dev.16",
3
+ "version": "7.3.0-dev.18",
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",
@@ -47,16 +47,16 @@
47
47
  "copy": "node ../../scripts/copy.mjs"
48
48
  },
49
49
  "dependencies": {
50
- "@mikro-orm/sql": "7.3.0-dev.16",
51
- "kysely": "0.29.6",
52
- "mysql2": "3.24.4",
50
+ "@mikro-orm/sql": "7.3.0-dev.18",
51
+ "kysely": "0.29.8",
52
+ "mysql2": "3.24.6",
53
53
  "sqlstring": "2.3.3"
54
54
  },
55
55
  "devDependencies": {
56
- "@mikro-orm/core": "^7.2.3"
56
+ "@mikro-orm/core": "^7.2.6"
57
57
  },
58
58
  "peerDependencies": {
59
- "@mikro-orm/core": "7.3.0-dev.16"
59
+ "@mikro-orm/core": "7.3.0-dev.18"
60
60
  },
61
61
  "engines": {
62
62
  "node": ">= 22.17.0"