@mikro-orm/mysql 7.1.0-dev.3 → 7.1.0-dev.31

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.
@@ -11,12 +11,18 @@ export class MySqlConnection extends AbstractSqlConnection {
11
11
  const innerPool = createPool({ ...options, password: initialPassword });
12
12
  // mysql2 reads pool.config.connectionConfig.password when creating new physical
13
13
  // connections, so updating it before getConnection() ensures fresh tokens are used.
14
- // Existing idle connections are already authenticated and unaffected.
14
+ // Existing idle connections are already authenticated and unaffected, so we skip
15
+ // the callback when the pool has a free connection to reuse.
15
16
  const pool = {
16
17
  getConnection(cb) {
18
+ const inner = innerPool;
19
+ if ((inner._freeConnections?.length ?? 0) > 0) {
20
+ innerPool.getConnection(cb);
21
+ return;
22
+ }
17
23
  Promise.resolve(password())
18
24
  .then(pw => {
19
- innerPool.config.connectionConfig.password = pw;
25
+ inner.config.connectionConfig.password = pw;
20
26
  innerPool.getConnection(cb);
21
27
  })
22
28
  .catch(err => cb(err, undefined));
@@ -40,6 +46,17 @@ export class MySqlConnection extends AbstractSqlConnection {
40
46
  const pool = this.config.get('pool');
41
47
  ret.connectionLimit = pool?.max;
42
48
  ret.idleTimeout = pool?.idleTimeoutMillis;
49
+ // mysql2 only runs idle cleanup when `maxIdle < connectionLimit`; its default has
50
+ // them equal, so `idleTimeout` alone is a no-op. When the user opts into idle
51
+ // cleanup via `pool.idleTimeoutMillis`, default `maxIdle` to `pool.min ?? 0` so
52
+ // idle connections actually drain. A misconfigured `pool.min > pool.max` is
53
+ // clamped below `pool.max` so cleanup still runs. Explicit `driverOptions.maxIdle`
54
+ // still wins because `overrides` is merged in last.
55
+ if (pool?.idleTimeoutMillis != null) {
56
+ const min = pool.min ?? 0;
57
+ const max = pool.max;
58
+ ret.maxIdle = max != null && min > max ? Math.max(0, max - 1) : min;
59
+ }
43
60
  if (this.config.get('multipleStatements')) {
44
61
  ret.multipleStatements = this.config.get('multipleStatements');
45
62
  }
@@ -1,5 +1,5 @@
1
- import { type AnyEntity, type EntityClass, type EntitySchema, MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType } from '@mikro-orm/core';
2
- import type { SqlEntityManager } from '@mikro-orm/sql';
1
+ import { type AnyEntity, type EntityClass, type EntitySchema, type MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType } from '@mikro-orm/core';
2
+ import { SqlMikroORM, type SqlEntityManager } from '@mikro-orm/sql';
3
3
  import { MySqlDriver } from './MySqlDriver.js';
4
4
  /** Configuration options for the MySQL driver. */
5
5
  export type MySqlOptions<EM extends SqlEntityManager<MySqlDriver> = SqlEntityManager<MySqlDriver>, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> = Partial<Options<MySqlDriver, EM, Entities>>;
@@ -8,7 +8,7 @@ export declare function defineMySqlConfig<EM extends SqlEntityManager<MySqlDrive
8
8
  /**
9
9
  * @inheritDoc
10
10
  */
11
- export declare class MySqlMikroORM<EM extends SqlEntityManager<MySqlDriver> = SqlEntityManager<MySqlDriver>, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends MikroORM<MySqlDriver, EM, Entities> {
11
+ export declare class MySqlMikroORM<EM extends SqlEntityManager<MySqlDriver> = SqlEntityManager<MySqlDriver>, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends SqlMikroORM<MySqlDriver, EM, Entities> {
12
12
  /**
13
13
  * @inheritDoc
14
14
  */
package/MySqlMikroORM.js CHANGED
@@ -1,4 +1,5 @@
1
- import { defineConfig, MikroORM, } from '@mikro-orm/core';
1
+ import { defineConfig, } from '@mikro-orm/core';
2
+ import { SqlMikroORM } from '@mikro-orm/sql';
2
3
  import { MySqlDriver } from './MySqlDriver.js';
3
4
  /** Creates a type-safe configuration object for the MySQL driver. */
4
5
  export function defineMySqlConfig(options) {
@@ -7,7 +8,7 @@ export function defineMySqlConfig(options) {
7
8
  /**
8
9
  * @inheritDoc
9
10
  */
10
- export class MySqlMikroORM extends MikroORM {
11
+ export class MySqlMikroORM extends SqlMikroORM {
11
12
  /**
12
13
  * @inheritDoc
13
14
  */
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  <a href="https://mikro-orm.io"><img src="https://raw.githubusercontent.com/mikro-orm/mikro-orm/master/docs/static/img/logo-readme.svg?sanitize=true" alt="MikroORM" /></a>
3
3
  </h1>
4
4
 
5
- TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL, SQLite (including libSQL), MSSQL and Oracle databases.
5
+ TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL (including CockroachDB and PGlite), SQLite (including libSQL), MSSQL and Oracle databases.
6
6
 
7
7
  > Heavily inspired by [Doctrine](https://www.doctrine-project.org/) and [Hibernate](https://hibernate.org/).
8
8
 
@@ -19,6 +19,7 @@ Install a driver package for your database:
19
19
 
20
20
  ```sh
21
21
  npm install @mikro-orm/postgresql # PostgreSQL
22
+ npm install @mikro-orm/pglite # PGlite (embedded PostgreSQL in WASM)
22
23
  npm install @mikro-orm/mysql # MySQL
23
24
  npm install @mikro-orm/mariadb # MariaDB
24
25
  npm install @mikro-orm/sqlite # SQLite
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/mysql",
3
- "version": "7.1.0-dev.3",
3
+ "version": "7.1.0-dev.31",
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.1.0-dev.3",
51
- "kysely": "0.28.16",
52
- "mysql2": "3.22.1",
50
+ "@mikro-orm/sql": "7.1.0-dev.31",
51
+ "kysely": "0.29.0",
52
+ "mysql2": "3.22.3",
53
53
  "sqlstring": "2.3.3"
54
54
  },
55
55
  "devDependencies": {
56
- "@mikro-orm/core": "^7.0.11"
56
+ "@mikro-orm/core": "^7.0.15"
57
57
  },
58
58
  "peerDependencies": {
59
- "@mikro-orm/core": "7.1.0-dev.3"
59
+ "@mikro-orm/core": "7.1.0-dev.31"
60
60
  },
61
61
  "engines": {
62
62
  "node": ">= 22.17.0"