@mikro-orm/mssql 7.1.3-dev.5 → 7.1.3

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.
Files changed (2) hide show
  1. package/MsSqlConnection.js +30 -3
  2. package/package.json +4 -4
@@ -1,7 +1,33 @@
1
1
  import { AbstractSqlConnection, DatabaseSchema, Utils, } from '@mikro-orm/sql';
2
- import { MssqlDialect } from 'kysely';
2
+ import { MssqlDialect, } from 'kysely';
3
3
  import * as Tedious from 'tedious';
4
4
  import * as Tarn from 'tarn';
5
+ /**
6
+ * Kysely's `MssqlDialect` has no native `onReserveConnection` hook, so we wrap the
7
+ * driver's `acquireConnection` to fire it on every pool checkout (e.g. to set the
8
+ * session context for row-level security).
9
+ */
10
+ class MsSqlReserveDialect extends MssqlDialect {
11
+ #onReserveConnection;
12
+ constructor(config, onReserveConnection) {
13
+ super(config);
14
+ this.#onReserveConnection = onReserveConnection;
15
+ }
16
+ createDriver() {
17
+ const driver = super.createDriver();
18
+ const onReserveConnection = this.#onReserveConnection;
19
+ if (!onReserveConnection) {
20
+ return driver;
21
+ }
22
+ const acquireConnection = driver.acquireConnection.bind(driver);
23
+ driver.acquireConnection = async (options) => {
24
+ const connection = await acquireConnection(options);
25
+ await onReserveConnection(connection);
26
+ return connection;
27
+ };
28
+ return driver;
29
+ }
30
+ }
5
31
  /** Microsoft SQL Server database connection using the `tedious` driver. */
6
32
  export class MsSqlConnection extends AbstractSqlConnection {
7
33
  createKyselyDialect(overrides) {
@@ -12,7 +38,8 @@ export class MsSqlConnection extends AbstractSqlConnection {
12
38
  }, this.config.get('pool'));
13
39
  const password = options.authentication?.options?.password;
14
40
  const onCreateConnection = this.options.onCreateConnection ?? this.config.get('onCreateConnection');
15
- return new MssqlDialect({
41
+ const onReserveConnection = this.options.onReserveConnection ?? this.config.get('onReserveConnection');
42
+ return new MsSqlReserveDialect({
16
43
  tarn: { ...Tarn, options: poolOptions },
17
44
  tedious: {
18
45
  ...Tedious,
@@ -24,7 +51,7 @@ export class MsSqlConnection extends AbstractSqlConnection {
24
51
  return connection;
25
52
  },
26
53
  },
27
- });
54
+ }, onReserveConnection);
28
55
  }
29
56
  mapOptions(overrides) {
30
57
  const options = this.getConnectionOptions();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/mssql",
3
- "version": "7.1.3-dev.5",
3
+ "version": "7.1.3",
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,17 +47,17 @@
47
47
  "copy": "node ../../scripts/copy.mjs"
48
48
  },
49
49
  "dependencies": {
50
- "@mikro-orm/sql": "7.1.3-dev.5",
50
+ "@mikro-orm/sql": "7.1.3",
51
51
  "kysely": "0.29.2",
52
52
  "tarn": "3.0.2",
53
53
  "tedious": "19.2.1",
54
54
  "tsqlstring": "1.0.1"
55
55
  },
56
56
  "devDependencies": {
57
- "@mikro-orm/core": "^7.1.2"
57
+ "@mikro-orm/core": "^7.1.3"
58
58
  },
59
59
  "peerDependencies": {
60
- "@mikro-orm/core": "7.1.3-dev.5"
60
+ "@mikro-orm/core": "7.1.3"
61
61
  },
62
62
  "engines": {
63
63
  "node": ">= 22.17.0"