@mikro-orm/mysql 7.0.12-dev.1 → 7.0.12-dev.11

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.
@@ -3,7 +3,7 @@ import { type PoolOptions } from 'mysql2';
3
3
  import { AbstractSqlConnection, type TransactionEventBroadcaster } from '@mikro-orm/sql';
4
4
  /** MySQL database connection using the `mysql2` driver. */
5
5
  export declare class MySqlConnection extends AbstractSqlConnection {
6
- createKyselyDialect(overrides: PoolOptions): MysqlDialect;
6
+ createKyselyDialect(overrides: PoolOptions): Promise<MysqlDialect>;
7
7
  mapOptions(overrides: PoolOptions): PoolOptions;
8
8
  commit(ctx: ControlledTransaction<any, any>, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>;
9
9
  }
@@ -1,17 +1,32 @@
1
1
  import { MysqlDialect } from 'kysely';
2
2
  import { createPool } from 'mysql2';
3
- import { Utils, AbstractSqlConnection } from '@mikro-orm/sql';
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
- createKyselyDialect(overrides) {
6
+ async createKyselyDialect(overrides) {
7
7
  const options = this.mapOptions(overrides);
8
8
  const password = options.password;
9
9
  if (typeof password === 'function') {
10
+ const initialPassword = await password();
11
+ const innerPool = createPool({ ...options, password: initialPassword });
12
+ // mysql2 reads pool.config.connectionConfig.password when creating new physical
13
+ // connections, so updating it before getConnection() ensures fresh tokens are used.
14
+ // Existing idle connections are already authenticated and unaffected.
15
+ const pool = {
16
+ getConnection(cb) {
17
+ Promise.resolve(password())
18
+ .then(pw => {
19
+ innerPool.config.connectionConfig.password = pw;
20
+ innerPool.getConnection(cb);
21
+ })
22
+ .catch(err => cb(err, undefined));
23
+ },
24
+ end(cb) {
25
+ innerPool.end(cb);
26
+ },
27
+ };
10
28
  return new MysqlDialect({
11
- pool: async () => createPool({
12
- ...options,
13
- password: await password(),
14
- }),
29
+ pool,
15
30
  onCreateConnection: this.options.onCreateConnection ?? this.config.get('onCreateConnection'),
16
31
  });
17
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/mysql",
3
- "version": "7.0.12-dev.1",
3
+ "version": "7.0.12-dev.11",
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.0.12-dev.1",
50
+ "@mikro-orm/sql": "7.0.12-dev.11",
51
51
  "kysely": "0.28.16",
52
- "mysql2": "3.22.0",
52
+ "mysql2": "3.22.1",
53
53
  "sqlstring": "2.3.3"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@mikro-orm/core": "^7.0.11"
57
57
  },
58
58
  "peerDependencies": {
59
- "@mikro-orm/core": "7.0.12-dev.1"
59
+ "@mikro-orm/core": "7.0.12-dev.11"
60
60
  },
61
61
  "engines": {
62
62
  "node": ">= 22.17.0"