@mikro-orm/mysql 7.3.0-dev.13 → 7.3.0-dev.15
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 +6 -0
- package/MySqlConnection.js +20 -3
- package/package.json +3 -3
package/MySqlConnection.d.ts
CHANGED
|
@@ -6,6 +6,12 @@ import { AbstractSqlConnection, type TransactionEventBroadcaster } from '@mikro-
|
|
|
6
6
|
export declare class MySqlConnection extends AbstractSqlConnection {
|
|
7
7
|
#private;
|
|
8
8
|
createKyselyDialect(overrides: PoolOptions): Promise<MysqlDialect>;
|
|
9
|
+
/**
|
|
10
|
+
* `mysql2` uses the `timezone` option only to convert `Date` values on the client, so the session
|
|
11
|
+
* time zone (and with it `now()` or `current_timestamp` defaults) would still follow the server.
|
|
12
|
+
* Pin it on every new connection, before the user-provided `onCreateConnection` hook runs.
|
|
13
|
+
*/
|
|
14
|
+
private getOnCreateConnection;
|
|
9
15
|
/** Returns the `mysql2` connection pool backing this connection. */
|
|
10
16
|
getNativeClient(): Promise<Pool>;
|
|
11
17
|
mapOptions(overrides: PoolOptions): PoolOptions;
|
package/MySqlConnection.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MysqlDialect, } from 'kysely';
|
|
1
|
+
import { CompiledQuery, MysqlDialect, } from 'kysely';
|
|
2
2
|
import { createConnection, createPool } from 'mysql2';
|
|
3
3
|
import { Utils, AbstractSqlConnection, } from '@mikro-orm/sql';
|
|
4
4
|
/** MySQL database connection using the `mysql2` driver. */
|
|
@@ -11,6 +11,7 @@ export class MySqlConnection extends AbstractSqlConnection {
|
|
|
11
11
|
async createKyselyDialect(overrides) {
|
|
12
12
|
const options = this.mapOptions(overrides);
|
|
13
13
|
const password = options.password;
|
|
14
|
+
const onCreateConnection = this.getOnCreateConnection(options.timezone);
|
|
14
15
|
if (typeof password === 'function') {
|
|
15
16
|
const initialPassword = await password();
|
|
16
17
|
const innerPool = createPool({ ...options, password: initialPassword });
|
|
@@ -41,7 +42,7 @@ export class MySqlConnection extends AbstractSqlConnection {
|
|
|
41
42
|
return new MysqlDialect({
|
|
42
43
|
pool,
|
|
43
44
|
controlConnection: MySqlConnection.#controlConnection,
|
|
44
|
-
onCreateConnection
|
|
45
|
+
onCreateConnection,
|
|
45
46
|
onReserveConnection: this.options.onReserveConnection ?? this.config.get('onReserveConnection'),
|
|
46
47
|
});
|
|
47
48
|
}
|
|
@@ -49,10 +50,26 @@ export class MySqlConnection extends AbstractSqlConnection {
|
|
|
49
50
|
return new MysqlDialect({
|
|
50
51
|
pool: this.#pool,
|
|
51
52
|
controlConnection: MySqlConnection.#controlConnection,
|
|
52
|
-
onCreateConnection
|
|
53
|
+
onCreateConnection,
|
|
53
54
|
onReserveConnection: this.options.onReserveConnection ?? this.config.get('onReserveConnection'),
|
|
54
55
|
});
|
|
55
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* `mysql2` uses the `timezone` option only to convert `Date` values on the client, so the session
|
|
59
|
+
* time zone (and with it `now()` or `current_timestamp` defaults) would still follow the server.
|
|
60
|
+
* Pin it on every new connection, before the user-provided `onCreateConnection` hook runs.
|
|
61
|
+
*/
|
|
62
|
+
getOnCreateConnection(timezone) {
|
|
63
|
+
const hook = this.options.onCreateConnection ?? this.config.get('onCreateConnection');
|
|
64
|
+
const sessionTimezone = timezone === 'Z' ? '+00:00' : timezone;
|
|
65
|
+
if (!sessionTimezone || sessionTimezone === 'local') {
|
|
66
|
+
return hook;
|
|
67
|
+
}
|
|
68
|
+
return async (connection) => {
|
|
69
|
+
await connection.executeQuery(CompiledQuery.raw('set time_zone = ?', [sessionTimezone]));
|
|
70
|
+
await hook?.(connection);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
56
73
|
/** Returns the `mysql2` connection pool backing this connection. */
|
|
57
74
|
async getNativeClient() {
|
|
58
75
|
await this.ensureConnection();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/mysql",
|
|
3
|
-
"version": "7.3.0-dev.
|
|
3
|
+
"version": "7.3.0-dev.15",
|
|
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.3.0-dev.
|
|
50
|
+
"@mikro-orm/sql": "7.3.0-dev.15",
|
|
51
51
|
"kysely": "0.29.6",
|
|
52
52
|
"mysql2": "3.24.4",
|
|
53
53
|
"sqlstring": "2.3.3"
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@mikro-orm/core": "^7.2.3"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@mikro-orm/core": "7.3.0-dev.
|
|
59
|
+
"@mikro-orm/core": "7.3.0-dev.15"
|
|
60
60
|
},
|
|
61
61
|
"engines": {
|
|
62
62
|
"node": ">= 22.17.0"
|