@mikro-orm/mysql 7.2.0-dev.4 → 7.2.0-dev.6
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/MySqlConnection.d.ts +3 -1
- package/MySqlConnection.js +10 -1
- package/package.json +3 -3
package/MySqlConnection.d.ts
CHANGED
|
@@ -1,11 +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
7
|
#private;
|
|
8
8
|
createKyselyDialect(overrides: PoolOptions): Promise<MysqlDialect>;
|
|
9
|
+
/** Returns the `mysql2` connection pool backing this connection. */
|
|
10
|
+
getNativeClient(): Promise<Pool>;
|
|
9
11
|
mapOptions(overrides: PoolOptions): PoolOptions;
|
|
10
12
|
callRoutine<T>(routine: Routine, args?: Record<string, unknown>, ctx?: Transaction): Promise<T>;
|
|
11
13
|
commit(ctx: ControlledTransaction<any, any>, eventBroadcaster?: TransactionEventBroadcaster): Promise<void>;
|
package/MySqlConnection.js
CHANGED
|
@@ -7,12 +7,15 @@ export class MySqlConnection extends AbstractSqlConnection {
|
|
|
7
7
|
// abort doesn't have to wait for an idle pool connection — or, inside a transaction, for the very
|
|
8
8
|
// query it is meant to cancel. Postgres gets one from its pool by default, mysql2 does not.
|
|
9
9
|
static #controlConnection = createConnection;
|
|
10
|
+
#pool;
|
|
10
11
|
async createKyselyDialect(overrides) {
|
|
11
12
|
const options = this.mapOptions(overrides);
|
|
12
13
|
const password = options.password;
|
|
13
14
|
if (typeof password === 'function') {
|
|
14
15
|
const initialPassword = await password();
|
|
15
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;
|
|
16
19
|
// mysql2 reads pool.config.connectionConfig.password when creating new physical
|
|
17
20
|
// connections, so updating it before getConnection() ensures fresh tokens are used.
|
|
18
21
|
// Existing idle connections are already authenticated and unaffected, so we skip
|
|
@@ -42,13 +45,19 @@ export class MySqlConnection extends AbstractSqlConnection {
|
|
|
42
45
|
onReserveConnection: this.options.onReserveConnection ?? this.config.get('onReserveConnection'),
|
|
43
46
|
});
|
|
44
47
|
}
|
|
48
|
+
this.#pool = createPool(options);
|
|
45
49
|
return new MysqlDialect({
|
|
46
|
-
pool:
|
|
50
|
+
pool: this.#pool,
|
|
47
51
|
controlConnection: MySqlConnection.#controlConnection,
|
|
48
52
|
onCreateConnection: this.options.onCreateConnection ?? this.config.get('onCreateConnection'),
|
|
49
53
|
onReserveConnection: this.options.onReserveConnection ?? this.config.get('onReserveConnection'),
|
|
50
54
|
});
|
|
51
55
|
}
|
|
56
|
+
/** Returns the `mysql2` connection pool backing this connection. */
|
|
57
|
+
async getNativeClient() {
|
|
58
|
+
await this.ensureConnection();
|
|
59
|
+
return this.requireNativeClient(this.#pool);
|
|
60
|
+
}
|
|
52
61
|
mapOptions(overrides) {
|
|
53
62
|
const ret = { ...this.getConnectionOptions() };
|
|
54
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.
|
|
3
|
+
"version": "7.2.0-dev.6",
|
|
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,7 +47,7 @@
|
|
|
47
47
|
"copy": "node ../../scripts/copy.mjs"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@mikro-orm/sql": "7.2.0-dev.
|
|
50
|
+
"@mikro-orm/sql": "7.2.0-dev.6",
|
|
51
51
|
"kysely": "0.29.4",
|
|
52
52
|
"mysql2": "3.23.2",
|
|
53
53
|
"sqlstring": "2.3.3"
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@mikro-orm/core": "^7.1.11"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@mikro-orm/core": "7.2.0-dev.
|
|
59
|
+
"@mikro-orm/core": "7.2.0-dev.6"
|
|
60
60
|
},
|
|
61
61
|
"engines": {
|
|
62
62
|
"node": ">= 22.17.0"
|