@mikro-orm/postgresql 7.2.6-dev.17 → 7.2.6-dev.19

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.
@@ -16,8 +16,8 @@ export declare class PostgreSqlConnection extends AbstractSqlConnection {
16
16
  * from a client while that client is checked out, deliberately leaving errors to whoever holds it,
17
17
  * and it re-emits errors of idle clients on the pool itself. The query in flight still rejects on
18
18
  * its own. An idle client is already discarded by the pool by the time we see it, a checked-out one
19
- * is released here, as kysely's `ControlledTransaction` only releases after a successful
20
- * commit/rollback (kysely-org/kysely#1990), which a dead connection never gets.
19
+ * is released here, as kysely's `ControlledTransaction` only releases after a commit or a rollback,
20
+ * which a transaction left open on a dead connection may never get.
21
21
  */
22
22
  private handlePoolErrors;
23
23
  /** Applies the active EM's session context (or resets it) on every pooled connection acquire. */
@@ -1,15 +1,36 @@
1
- import { Pool, TypeOverrides } from 'pg';
1
+ import { Client, Pool, TypeOverrides } from 'pg';
2
2
  import Cursor from 'pg-cursor';
3
3
  import { CompiledQuery, PostgresDialect } from 'kysely';
4
4
  import array from 'postgres-array';
5
5
  import { AbstractSqlConnection, createPostgreSqlTypeParsers, Utils } from '@mikro-orm/sql';
6
+ /**
7
+ * PostgreSQL answers `COMMIT` of an aborted transaction with the command tag `ROLLBACK` instead of an error,
8
+ * and kysely drops the tag, so the failed commit is rejected here, like any other commit the server refused.
9
+ */
10
+ class PostgreSqlClient extends Client {
11
+ query(...args) {
12
+ const res = super.query.apply(this, args);
13
+ // kysely sends a top-level commit as exactly `commit`, a callback-style call returns nothing
14
+ if (args[0] !== 'commit' || !res) {
15
+ return res;
16
+ }
17
+ return res.then((result) => {
18
+ if (result.command === 'ROLLBACK') {
19
+ throw Object.assign(new Error('current transaction is aborted, COMMIT was answered with ROLLBACK'), {
20
+ code: '25P02',
21
+ });
22
+ }
23
+ return result;
24
+ });
25
+ }
26
+ }
6
27
  /** PostgreSQL database connection using the `pg` driver. */
7
28
  export class PostgreSqlConnection extends AbstractSqlConnection {
8
29
  #pool;
9
30
  createKyselyDialect(overrides) {
10
31
  const { onPoolCreated, ...poolOverrides } = (overrides ?? {});
11
32
  const options = this.mapOptions(poolOverrides);
12
- const pool = new Pool(options);
33
+ const pool = new Pool({ Client: PostgreSqlClient, ...options });
13
34
  this.#pool = pool;
14
35
  this.handlePoolErrors(pool);
15
36
  void onPoolCreated?.(pool);
@@ -36,8 +57,8 @@ export class PostgreSqlConnection extends AbstractSqlConnection {
36
57
  * from a client while that client is checked out, deliberately leaving errors to whoever holds it,
37
58
  * and it re-emits errors of idle clients on the pool itself. The query in flight still rejects on
38
59
  * its own. An idle client is already discarded by the pool by the time we see it, a checked-out one
39
- * is released here, as kysely's `ControlledTransaction` only releases after a successful
40
- * commit/rollback (kysely-org/kysely#1990), which a dead connection never gets.
60
+ * is released here, as kysely's `ControlledTransaction` only releases after a commit or a rollback,
61
+ * which a transaction left open on a dead connection may never get.
41
62
  */
42
63
  handlePoolErrors(pool) {
43
64
  const checkedOut = new WeakSet();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/postgresql",
3
- "version": "7.2.6-dev.17",
3
+ "version": "7.2.6-dev.19",
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.6-dev.17",
50
+ "@mikro-orm/sql": "7.2.6-dev.19",
51
51
  "kysely": "0.29.7",
52
52
  "pg": "8.23.1",
53
53
  "pg-cursor": "2.22.1",
@@ -59,7 +59,7 @@
59
59
  "@mikro-orm/core": "^7.2.5"
60
60
  },
61
61
  "peerDependencies": {
62
- "@mikro-orm/core": "7.2.6-dev.17"
62
+ "@mikro-orm/core": "7.2.6-dev.19"
63
63
  },
64
64
  "engines": {
65
65
  "node": ">= 22.17.0"