@mikro-orm/mysql 7.2.0-dev.1 → 7.2.0-dev.10

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.
@@ -1,10 +1,13 @@
1
1
  import { type ControlledTransaction, MysqlDialect } from 'kysely';
2
- import { type PoolOptions } from 'mysql2';
2
+ import { type Pool, type PoolOptions } from 'mysql2';
3
3
  import { type Routine, type Transaction } from '@mikro-orm/core';
4
4
  import { AbstractSqlConnection, type TransactionEventBroadcaster } from '@mikro-orm/sql';
5
5
  /** MySQL database connection using the `mysql2` driver. */
6
6
  export declare class MySqlConnection extends AbstractSqlConnection {
7
+ #private;
7
8
  createKyselyDialect(overrides: PoolOptions): Promise<MysqlDialect>;
9
+ /** Returns the `mysql2` connection pool backing this connection. */
10
+ getNativeClient(): Promise<Pool>;
8
11
  mapOptions(overrides: PoolOptions): PoolOptions;
9
12
  callRoutine<T>(routine: Routine, args?: Record<string, unknown>, ctx?: Transaction): Promise<T>;
10
13
  commit(ctx: ControlledTransaction<any, any>, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>;
@@ -1,14 +1,21 @@
1
- import { MysqlDialect } from 'kysely';
2
- import { createPool } from 'mysql2';
1
+ import { MysqlDialect, } from 'kysely';
2
+ import { createConnection, createPool } from 'mysql2';
3
3
  import { Utils, AbstractSqlConnection, } from '@mikro-orm/sql';
4
4
  /** MySQL database connection using the `mysql2` driver. */
5
5
  export class MySqlConnection extends AbstractSqlConnection {
6
+ // Kysely sends `cancel query`/`kill session` over this connection rather than over the pool, so an
7
+ // abort doesn't have to wait for an idle pool connection — or, inside a transaction, for the very
8
+ // query it is meant to cancel. Postgres gets one from its pool by default, mysql2 does not.
9
+ static #controlConnection = createConnection;
10
+ #pool;
6
11
  async createKyselyDialect(overrides) {
7
12
  const options = this.mapOptions(overrides);
8
13
  const password = options.password;
9
14
  if (typeof password === 'function') {
10
15
  const initialPassword = await password();
11
16
  const innerPool = createPool({ ...options, password: initialPassword });
17
+ // the wrapper below is a kysely-shaped shim, so expose the real mysql2 pool
18
+ this.#pool = innerPool;
12
19
  // mysql2 reads pool.config.connectionConfig.password when creating new physical
13
20
  // connections, so updating it before getConnection() ensures fresh tokens are used.
14
21
  // Existing idle connections are already authenticated and unaffected, so we skip
@@ -33,16 +40,24 @@ export class MySqlConnection extends AbstractSqlConnection {
33
40
  };
34
41
  return new MysqlDialect({
35
42
  pool,
43
+ controlConnection: MySqlConnection.#controlConnection,
36
44
  onCreateConnection: this.options.onCreateConnection ?? this.config.get('onCreateConnection'),
37
45
  onReserveConnection: this.options.onReserveConnection ?? this.config.get('onReserveConnection'),
38
46
  });
39
47
  }
48
+ this.#pool = createPool(options);
40
49
  return new MysqlDialect({
41
- pool: createPool(options),
50
+ pool: this.#pool,
51
+ controlConnection: MySqlConnection.#controlConnection,
42
52
  onCreateConnection: this.options.onCreateConnection ?? this.config.get('onCreateConnection'),
43
53
  onReserveConnection: this.options.onReserveConnection ?? this.config.get('onReserveConnection'),
44
54
  });
45
55
  }
56
+ /** Returns the `mysql2` connection pool backing this connection. */
57
+ async getNativeClient() {
58
+ await this.ensureConnection();
59
+ return this.requireNativeClient(this.#pool);
60
+ }
46
61
  mapOptions(overrides) {
47
62
  const ret = { ...this.getConnectionOptions() };
48
63
  const pool = this.config.get('pool');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/mysql",
3
- "version": "7.2.0-dev.1",
3
+ "version": "7.2.0-dev.10",
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.2.0-dev.1",
51
- "kysely": "0.29.4",
52
- "mysql2": "3.23.1",
50
+ "@mikro-orm/sql": "7.2.0-dev.10",
51
+ "kysely": "0.29.5",
52
+ "mysql2": "3.23.3",
53
53
  "sqlstring": "2.3.3"
54
54
  },
55
55
  "devDependencies": {
56
- "@mikro-orm/core": "^7.1.7"
56
+ "@mikro-orm/core": "^7.1.11"
57
57
  },
58
58
  "peerDependencies": {
59
- "@mikro-orm/core": "7.2.0-dev.1"
59
+ "@mikro-orm/core": "7.2.0-dev.10"
60
60
  },
61
61
  "engines": {
62
62
  "node": ">= 22.17.0"