@mikro-orm/postgresql 7.2.0-dev.1 → 7.2.0-dev.10

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.
@@ -1,10 +1,24 @@
1
- import { type PoolConfig } from 'pg';
1
+ import { Pool, type PoolConfig } from 'pg';
2
2
  import { PostgresDialect } from 'kysely';
3
3
  import { type Routine, type Transaction } from '@mikro-orm/core';
4
4
  import { AbstractSqlConnection } from '@mikro-orm/sql';
5
5
  /** PostgreSQL database connection using the `pg` driver. */
6
6
  export declare class PostgreSqlConnection extends AbstractSqlConnection {
7
+ #private;
7
8
  createKyselyDialect(overrides: PoolConfig): PostgresDialect;
9
+ /** Returns the `pg` connection pool backing this connection. */
10
+ getNativeClient(): Promise<Pool>;
11
+ /**
12
+ * Keeps a connection dropped by the server from taking the process down. `pg` reports such a drop
13
+ * as an `'error'` event, and an `'error'` event without a listener is a fatal uncaught exception.
14
+ *
15
+ * Both of the paths that emit one are unguarded by default: `pg-pool` removes its own listener
16
+ * from a client while that client is checked out, deliberately leaving errors to whoever holds it,
17
+ * and it re-emits errors of idle clients on the pool itself. The query in flight still rejects on
18
+ * its own, so there is nothing to do here beyond logging — the pool has already discarded the
19
+ * broken client by the time we see it.
20
+ */
21
+ private handlePoolErrors;
8
22
  mapOptions(overrides: PoolConfig): PoolConfig;
9
23
  callRoutine<T>(routine: Routine, args?: Record<string, unknown>, ctx?: Transaction): Promise<T>;
10
24
  private fetchRefcursors;
@@ -5,10 +5,13 @@ import array from 'postgres-array';
5
5
  import { AbstractSqlConnection, createPostgreSqlTypeParsers, Utils } from '@mikro-orm/sql';
6
6
  /** PostgreSQL database connection using the `pg` driver. */
7
7
  export class PostgreSqlConnection extends AbstractSqlConnection {
8
+ #pool;
8
9
  createKyselyDialect(overrides) {
9
10
  const { onPoolCreated, ...poolOverrides } = (overrides ?? {});
10
11
  const options = this.mapOptions(poolOverrides);
11
12
  const pool = new Pool(options);
13
+ this.#pool = pool;
14
+ this.handlePoolErrors(pool);
12
15
  void onPoolCreated?.(pool);
13
16
  return new PostgresDialect({
14
17
  pool,
@@ -17,6 +20,27 @@ export class PostgreSqlConnection extends AbstractSqlConnection {
17
20
  onReserveConnection: this.options.onReserveConnection ?? this.config.get('onReserveConnection'),
18
21
  });
19
22
  }
23
+ /** Returns the `pg` connection pool backing this connection. */
24
+ async getNativeClient() {
25
+ await this.ensureConnection();
26
+ return this.requireNativeClient(this.#pool);
27
+ }
28
+ /**
29
+ * Keeps a connection dropped by the server from taking the process down. `pg` reports such a drop
30
+ * as an `'error'` event, and an `'error'` event without a listener is a fatal uncaught exception.
31
+ *
32
+ * Both of the paths that emit one are unguarded by default: `pg-pool` removes its own listener
33
+ * from a client while that client is checked out, deliberately leaving errors to whoever holds it,
34
+ * and it re-emits errors of idle clients on the pool itself. The query in flight still rejects on
35
+ * its own, so there is nothing to do here beyond logging — the pool has already discarded the
36
+ * broken client by the time we see it.
37
+ */
38
+ handlePoolErrors(pool) {
39
+ pool.on('connect', client => {
40
+ client.on('error', e => this.logger.warn('info', `PostgreSQL connection error: ${e.message}`));
41
+ });
42
+ pool.on('error', e => this.logger.warn('info', `PostgreSQL pool error: ${e.message}`));
43
+ }
20
44
  mapOptions(overrides) {
21
45
  const ret = { ...this.getConnectionOptions() };
22
46
  const pool = this.config.get('pool');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/postgresql",
3
- "version": "7.2.0-dev.1",
3
+ "version": "7.2.0-dev.10",
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,19 +47,19 @@
47
47
  "copy": "node ../../scripts/copy.mjs"
48
48
  },
49
49
  "dependencies": {
50
- "@mikro-orm/sql": "7.2.0-dev.1",
51
- "kysely": "0.29.4",
52
- "pg": "8.22.0",
53
- "pg-cursor": "2.21.0",
50
+ "@mikro-orm/sql": "7.2.0-dev.10",
51
+ "kysely": "0.29.5",
52
+ "pg": "8.23.0",
53
+ "pg-cursor": "2.22.0",
54
54
  "postgres-array": "3.0.4",
55
55
  "postgres-date": "2.1.0",
56
56
  "postgres-interval": "4.1.0"
57
57
  },
58
58
  "devDependencies": {
59
- "@mikro-orm/core": "^7.1.7"
59
+ "@mikro-orm/core": "^7.1.11"
60
60
  },
61
61
  "peerDependencies": {
62
- "@mikro-orm/core": "7.2.0-dev.1"
62
+ "@mikro-orm/core": "7.2.0-dev.10"
63
63
  },
64
64
  "engines": {
65
65
  "node": ">= 22.17.0"