@m2k-5f/pgtx 2.6.0 → 2.6.2
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/README.md +214 -480
- package/dist/batch.d.ts +3 -2
- package/dist/batch.d.ts.map +1 -1
- package/dist/batch.js +9 -9
- package/dist/clauses/abstract.clause.d.ts.map +1 -1
- package/dist/connection.d.ts +42 -175
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +205 -290
- package/dist/error.d.ts +5 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/pool.d.ts +35 -192
- package/dist/pool.d.ts.map +1 -1
- package/dist/pool.js +70 -202
- package/dist/protocol/connection-response-reader.d.ts +3 -4
- package/dist/protocol/connection-response-reader.d.ts.map +1 -1
- package/dist/protocol/connection-response-reader.js +4 -2
- package/dist/protocol/socket-authorization.d.ts +1 -10
- package/dist/protocol/socket-authorization.d.ts.map +1 -1
- package/dist/protocol/socket-authorization.js +1 -4
- package/dist/protocol/socket-connector.d.ts +5 -5
- package/dist/protocol/socket-connector.d.ts.map +1 -1
- package/dist/protocol/socket-connector.js +24 -17
- package/dist/query.d.ts +17 -26
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +24 -27
- package/dist/transaction.d.ts +11 -4
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +24 -11
- package/dist/types.d.ts +59 -11
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/error.d.ts
CHANGED
|
@@ -15,7 +15,12 @@ export declare class PostgresError extends Error {
|
|
|
15
15
|
get isTimeout(): boolean;
|
|
16
16
|
get isConnectionFailure(): boolean;
|
|
17
17
|
}
|
|
18
|
+
export declare const ErrNonceMismatch: PostgresError;
|
|
19
|
+
export declare const ErrPasswordRequired: PostgresError;
|
|
20
|
+
export declare const ErrSocketFailedDuringAuth: PostgresError;
|
|
18
21
|
export declare const ErrQueryTimeout: PostgresError;
|
|
22
|
+
export declare const ErrPoolClosed: PostgresError;
|
|
23
|
+
export declare const ErrTransactionClosed: PostgresError;
|
|
19
24
|
export declare const ErrConnectionClosed: PostgresError;
|
|
20
25
|
export declare const ErrConnectionReconnecting: PostgresError;
|
|
21
26
|
//# sourceMappingURL=error.d.ts.map
|
package/dist/error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;IAEhB,OAAO,EAAE,MAAM;IACxB,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,MAAM;IAChB,KAAK,EAAE,MAAM;IACb,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,MAAM;IAChB,UAAU,EAAE,MAAM;gBART,OAAO,EAAE,MAAM,EACxB,IAAI,GAAE,MAAqB,EAC3B,MAAM,GAAE,MAAW,EACnB,QAAQ,GAAE,MAAW,EACrB,KAAK,GAAE,MAAW,EAClB,IAAI,GAAE,MAAW,EACjB,QAAQ,GAAE,MAAW,EACrB,QAAQ,GAAE,MAAW,EACrB,UAAU,GAAE,MAAW;IAQlC,IAAI,YAAY,IAAI,OAAO,CAE1B;IAID,IAAI,UAAU,IAAI,OAAO,CAExB;IAID,IAAI,qBAAqB,IAAI,OAAO,CAEnC;IAGD,IAAI,SAAS,IAAI,OAAO,CAEvB;IAGD,IAAI,mBAAmB,IAAI,OAAO,CAEjC;CACJ;AAED,eAAO,MAAM,eAAe,eAA8C,CAAA;AAE1E,eAAO,MAAM,mBAAmB,eAA8E,CAAA;AAC9G,eAAO,MAAM,yBAAyB,eAA2F,CAAA"}
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;IAEhB,OAAO,EAAE,MAAM;IACxB,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,MAAM;IAChB,KAAK,EAAE,MAAM;IACb,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,MAAM;IAChB,QAAQ,EAAE,MAAM;IAChB,UAAU,EAAE,MAAM;gBART,OAAO,EAAE,MAAM,EACxB,IAAI,GAAE,MAAqB,EAC3B,MAAM,GAAE,MAAW,EACnB,QAAQ,GAAE,MAAW,EACrB,KAAK,GAAE,MAAW,EAClB,IAAI,GAAE,MAAW,EACjB,QAAQ,GAAE,MAAW,EACrB,QAAQ,GAAE,MAAW,EACrB,UAAU,GAAE,MAAW;IAQlC,IAAI,YAAY,IAAI,OAAO,CAE1B;IAID,IAAI,UAAU,IAAI,OAAO,CAExB;IAID,IAAI,qBAAqB,IAAI,OAAO,CAEnC;IAGD,IAAI,SAAS,IAAI,OAAO,CAEvB;IAGD,IAAI,mBAAmB,IAAI,OAAO,CAEjC;CACJ;AAED,eAAO,MAAM,gBAAgB,eAAmF,CAAA;AAChH,eAAO,MAAM,mBAAmB,eAAqE,CAAA;AACrG,eAAO,MAAM,yBAAyB,eAAiD,CAAA;AAEvF,eAAO,MAAM,eAAe,eAA8C,CAAA;AAE1E,eAAO,MAAM,aAAa,eAAkE,CAAA;AAE5F,eAAO,MAAM,oBAAoB,eAA6E,CAAA;AAE9G,eAAO,MAAM,mBAAmB,eAA8E,CAAA;AAC9G,eAAO,MAAM,yBAAyB,eAA2F,CAAA"}
|
package/dist/error.js
CHANGED
|
@@ -31,6 +31,11 @@ export class PostgresError extends Error {
|
|
|
31
31
|
return this.code.startsWith('08') || this.code.startsWith('57') && this.code !== '57014';
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
+
export const ErrNonceMismatch = new PostgresError("Protocol violation: server nonce doesn't match client nonce");
|
|
35
|
+
export const ErrPasswordRequired = new PostgresError('The authorization method requires a password.');
|
|
36
|
+
export const ErrSocketFailedDuringAuth = new PostgresError("Socket failed during auth");
|
|
34
37
|
export const ErrQueryTimeout = new PostgresError('Query timeout', '57014');
|
|
38
|
+
export const ErrPoolClosed = new PostgresError("Pool is closed", 'pool_closed', '', "ERROR");
|
|
39
|
+
export const ErrTransactionClosed = new PostgresError("Transaction closed", "transaction_closed", '', "ERROR");
|
|
35
40
|
export const ErrConnectionClosed = new PostgresError("Connection is closed", 'connection_closed', "", "ERROR");
|
|
36
41
|
export const ErrConnectionReconnecting = new PostgresError("Connection are reconnecting", "connection_reconnecting", "", "ERROR");
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EACH,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,mBAAmB,EAEnB,WAAW,EACX,aAAa,EACb,cAAc,EACjB,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C;;;GAGG;AACH,eAAO,MAAM,GAAG;IACZ;;;;;;;;;;;OAWG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;;;;;KAWC;;IAGD;;;;;;;;;;OAUG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;;;;;;;;;;;;;OAmBG;;CAEN,CAAA;AAGD;;;GAGG;AAEH,OAAO,EAAE,UAAU,IAAI,UAAU,EAAE,CAAA;AAEnC,OAAO,EAAE,WAAW,IAAI,WAAW,EAAE,CAAA;AAErC,OAAO,EAAE,QAAQ,IAAI,IAAI,EAAE,CAAA;AAG3B,cAAc,WAAW,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EACH,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,mBAAmB,EAEnB,WAAW,EACX,aAAa,EACb,cAAc,EACjB,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C;;;GAGG;AACH,eAAO,MAAM,GAAG;IACZ;;;;;;;;;;;OAWG;;IAGH;;;;;;OAMG;;IAGH;;;;;;OAMG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;;;;;KAWC;;IAGD;;;;;;;;;;OAUG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;;;;;;;;;;;;;OAmBG;;CAEN,CAAA;AAGD;;;GAGG;AAEH,OAAO,EAAE,UAAU,IAAI,UAAU,EAAE,CAAA;AAEnC,OAAO,EAAE,WAAW,IAAI,WAAW,EAAE,CAAA;AAErC,OAAO,EAAE,QAAQ,IAAI,IAAI,EAAE,CAAA;AAG3B,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA"}
|
package/dist/index.js
CHANGED
package/dist/pool.d.ts
CHANGED
|
@@ -1,238 +1,81 @@
|
|
|
1
|
-
import { Connection
|
|
1
|
+
import { Connection } from "./connection";
|
|
2
2
|
import { Transaction } from "./transaction";
|
|
3
3
|
import { Future } from "fluent-future";
|
|
4
4
|
import { PostgresError } from "./error";
|
|
5
|
-
|
|
6
|
-
max?: number;
|
|
7
|
-
};
|
|
5
|
+
import { PoolPartialConfig, Row } from "./types";
|
|
8
6
|
/**
|
|
9
|
-
*
|
|
10
|
-
* Manages a connection pool and provides high-level API for queries and transactions.
|
|
7
|
+
* Connection pool and the main entry point for Pgtx.
|
|
11
8
|
*
|
|
12
9
|
* @example
|
|
13
|
-
*
|
|
14
|
-
* const pool = new Pool({
|
|
15
|
-
* host: 'localhost',
|
|
16
|
-
* user: 'postgres',
|
|
17
|
-
* password: 'postgres',
|
|
18
|
-
* database: 'test',
|
|
19
|
-
* max: 10
|
|
20
|
-
* })
|
|
21
|
-
*
|
|
22
|
-
* // Simple query
|
|
10
|
+
* const pool = new Pool({ host: 'localhost', user: 'postgres', password: 'postgres', database: 'test', max: 10 })
|
|
23
11
|
* const users = await pool.query`SELECT * FROM users WHERE id = ${1}`
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* const result = await pool.begin(async tx => {
|
|
27
|
-
* await tx.query`INSERT INTO users ...`
|
|
28
|
-
* return 'success'
|
|
29
|
-
* })
|
|
30
|
-
*
|
|
31
|
-
* // Manual acquire/release
|
|
32
|
-
* const conn = await pool.acquire()
|
|
33
|
-
* try {
|
|
34
|
-
* await conn.query`SELECT 1`
|
|
35
|
-
* } finally {
|
|
36
|
-
* pool.release(conn)
|
|
37
|
-
* }
|
|
38
|
-
*
|
|
39
|
-
* // Clean up
|
|
40
|
-
* pool.close()
|
|
41
|
-
* ```
|
|
12
|
+
* await pool.begin(async tx => tx.query`INSERT INTO users ...`)
|
|
13
|
+
* await pool.close()
|
|
42
14
|
*/
|
|
43
15
|
export declare class Pool {
|
|
44
16
|
private _available;
|
|
45
|
-
private
|
|
46
|
-
private _max;
|
|
17
|
+
private config;
|
|
47
18
|
private _total;
|
|
48
19
|
private _waiting;
|
|
49
|
-
private
|
|
50
|
-
|
|
51
|
-
constructor(params: PoolParams);
|
|
20
|
+
private _isOpened;
|
|
21
|
+
constructor(config: PoolPartialConfig);
|
|
52
22
|
/**
|
|
53
|
-
* Acquires a dedicated connection
|
|
54
|
-
*
|
|
55
|
-
* **Note:** You must call `pool.release(conn)` manually when finished.
|
|
56
|
-
* For most cases, prefer using `pool.query()` or `pool.begin()` which handle this automatically.
|
|
57
|
-
*
|
|
58
|
-
* @returns A connection from the pool or a new one if available.
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```ts
|
|
62
|
-
* const conn = await pool.acquire()
|
|
63
|
-
* try {
|
|
64
|
-
* await conn.query`SELECT 1`
|
|
65
|
-
* } finally {
|
|
66
|
-
* pool.release(conn)
|
|
67
|
-
* }
|
|
68
|
-
* ```
|
|
23
|
+
* Acquires a dedicated connection. Call `pool.release(conn)` when done —
|
|
24
|
+
* prefer `pool.query()`/`pool.begin()` where possible, they release automatically.
|
|
69
25
|
*/
|
|
70
26
|
acquire(): Future<Connection, PostgresError>;
|
|
71
27
|
/**
|
|
72
|
-
*
|
|
73
|
-
* directly on a single, dedicated `Connection` instance.
|
|
74
|
-
*
|
|
75
|
-
* Automatically borrows a free socket from the pool, forwards it to the provided callback function,
|
|
76
|
-
* and guarantees that the connection is released back to the pool once the execution completes,
|
|
77
|
-
* even if errors or unexpected exceptions are thrown. Prevents connection descriptor leaks.
|
|
78
|
-
*
|
|
79
|
-
* @template T The return type of the provided callback function.
|
|
80
|
-
* @param {(conn: Connection) => Promise<T>} fn A callback function that operates on the allocated Connection.
|
|
81
|
-
* @returns {Future<T, PostgresError>} A `Future` that resolves with the return value of the callback.
|
|
28
|
+
* Runs `fn` with a borrowed connection and releases it afterward, even on error.
|
|
82
29
|
*
|
|
83
30
|
* @example
|
|
84
|
-
*
|
|
85
|
-
* const status = await pool.withAcquire(async (conn) => {
|
|
86
|
-
* return await conn.query`SELECT pg_is_in_recovery()`;
|
|
87
|
-
* });
|
|
31
|
+
* const status = await pool.withAcquire(conn => conn.query`SELECT pg_is_in_recovery()`)
|
|
88
32
|
*/
|
|
89
33
|
withAcquire<T>(fn: (conn: Connection) => Promise<T>): Future<T, unknown>;
|
|
90
|
-
/**
|
|
91
|
-
* Releases the connection back to the pool.
|
|
92
|
-
*
|
|
93
|
-
* If there are pending `acquire()` calls, the connection is passed directly to the next waiter.
|
|
94
|
-
* Otherwise, it's added to the available connections queue.
|
|
95
|
-
*
|
|
96
|
-
* @param conn - The connection to release.
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```ts
|
|
100
|
-
* const conn = await pool.acquire()
|
|
101
|
-
* try {
|
|
102
|
-
* await conn.query`SELECT 1`
|
|
103
|
-
* } finally {
|
|
104
|
-
* pool.release(conn)
|
|
105
|
-
* }
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
34
|
+
/** Returns `conn` to the pool, or hands it directly to the next waiting `acquire()`. */
|
|
108
35
|
release(conn: Connection): void;
|
|
109
36
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* Automatically acquires a connection and handles `BEGIN`, `COMMIT`, and `ROLLBACK`.
|
|
113
|
-
* If the callback throws an error, the transaction is rolled back.
|
|
114
|
-
*
|
|
115
|
-
* @param txCallback - Async function that receives a `Transaction` instance.
|
|
116
|
-
* @returns The value returned from the callback.
|
|
37
|
+
* Runs `txCallback` inside a transaction on a borrowed connection, releasing it afterward.
|
|
117
38
|
*
|
|
118
39
|
* @example
|
|
119
|
-
*
|
|
120
|
-
* const result = await pool.begin(async tx => {
|
|
121
|
-
* await tx.query`INSERT INTO accounts (id, balance) VALUES (1, 100)`
|
|
40
|
+
* await pool.begin(async tx => {
|
|
122
41
|
* await tx.query`UPDATE accounts SET balance = balance - 10 WHERE id = 1`
|
|
123
|
-
* return { success: true }
|
|
124
42
|
* })
|
|
125
|
-
* ```
|
|
126
43
|
*/
|
|
127
44
|
begin<T>(txCallback: (transaction: Transaction) => Promise<T>): Future<T, unknown>;
|
|
128
45
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* Automatically acquires and releases a connection from the pool.
|
|
132
|
-
* For optimal performance, multiple queries can be pipelined through the same connection.
|
|
133
|
-
*
|
|
134
|
-
* @param templates - Tagged template string with SQL.
|
|
135
|
-
* @param args - Query parameters.
|
|
136
|
-
* @returns Array of rows with proper typing.
|
|
137
|
-
*
|
|
138
|
-
* @example
|
|
139
|
-
* ```ts
|
|
140
|
-
* // Simple query
|
|
141
|
-
* const users = await pool.query`SELECT * FROM users`
|
|
142
|
-
*
|
|
143
|
-
* // With parameters
|
|
144
|
-
* const user = await pool.query`SELECT * FROM users WHERE id = ${1}`
|
|
145
|
-
*
|
|
146
|
-
* // With typed result
|
|
147
|
-
* type User = { id: number, name: string }
|
|
148
|
-
* const users = await pool.query<User>`SELECT * FROM users`
|
|
149
|
-
* ```
|
|
150
|
-
*/
|
|
151
|
-
query<T extends Record<string, any>>(templates: TemplateStringsArray, ...args: any[]): Future<T[], PostgresError>;
|
|
152
|
-
/**
|
|
153
|
-
* Executes an SQL query in streaming mode.
|
|
154
|
-
*
|
|
155
|
-
* Data is streamed directly from the PostgreSQL binary network buffer into the Web Streams API
|
|
156
|
-
* (`ReadableStream`), bypassing any intermediate array allocation or row accumulation in the JS heap.
|
|
157
|
-
* This pattern provides a true Zero-Memory Footprint and is ideal for exporting massive tables
|
|
158
|
-
* or piping database payloads directly into HTTP responses (e.g., via `Bun.serve` or fetch `Response`).
|
|
159
|
-
*
|
|
160
|
-
* @template T The expected shape of a single row interface.
|
|
161
|
-
* @param {TemplateStringsArray} templates The SQL string parts from the tagged template literal.
|
|
162
|
-
* @param {...any} args The parameterized query arguments.
|
|
163
|
-
* @returns {ReadableStream<T>} Synchronously returns a native Web ReadableStream instance.
|
|
164
|
-
*
|
|
165
|
-
* @example
|
|
166
|
-
* // Streaming a giant table directly to an HTTP response (Bun.serve)
|
|
167
|
-
* const userStream = pool.stream<User>`SELECT id, name FROM users`;
|
|
168
|
-
* return new Response(userStream, { headers: { 'Content-Type': 'application/json' } });
|
|
46
|
+
* Runs a one-off query on a borrowed connection.
|
|
169
47
|
*
|
|
170
48
|
* @example
|
|
171
|
-
*
|
|
172
|
-
* const stream = pool.stream<User>`SELECT * FROM orders WHERE status = ${'processed'}`;
|
|
173
|
-
* for await (const row of stream) {
|
|
174
|
-
* console.log(row.id, row.amount); // Row object is eligible for GC immediately after iteration
|
|
175
|
-
* }
|
|
49
|
+
* const users = await pool.query<User>`SELECT * FROM users WHERE id = ${1}`
|
|
176
50
|
*/
|
|
177
|
-
|
|
51
|
+
query<T extends Row>(templates: TemplateStringsArray, ...args: any[]): Future<T[], PostgresError>;
|
|
52
|
+
/** Like {@link query}, but for statements that don't return rows. */
|
|
53
|
+
execute(templates: TemplateStringsArray, ...params: any[]): Future<void, PostgresError>;
|
|
178
54
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* @param channelName - The channel identifier
|
|
182
|
-
* @param payload - Optional string data (max 8000 bytes)
|
|
55
|
+
* Streams query results as a `ReadableStream`, without buffering rows in memory.
|
|
183
56
|
*
|
|
184
57
|
* @example
|
|
185
|
-
*
|
|
186
|
-
* await pool.notify('events', 'hello')
|
|
187
|
-
* ```
|
|
58
|
+
* for await (const row of pool.stream<User>`SELECT * FROM orders`) { ... }
|
|
188
59
|
*/
|
|
189
|
-
|
|
60
|
+
stream<T extends Row>(templates: TemplateStringsArray, ...args: any[]): ReadableStream<T>;
|
|
61
|
+
/** Sends a `pg_notify` message on `channelName` (payload ≤ 8000 bytes). */
|
|
62
|
+
notify(channelName: string, payload?: string): Future<void, PostgresError>;
|
|
190
63
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
* This method automatically claims a dedicated connection from the pool, registers the callback
|
|
194
|
-
* to handle incoming asynchronous database notices (`NotificationResponse` packets), and returns
|
|
195
|
-
* a lazy unsubscribe function wrapped in a `Future`.
|
|
196
|
-
*
|
|
197
|
-
* Invoking the returned unsubscribe function will automatically issue the `UNLISTEN` command
|
|
198
|
-
* to the database backend, clean up the memory callback, and safely release the connection back to the pool.
|
|
199
|
-
*
|
|
200
|
-
* @param {string} channel The name of the PostgreSQL notification channel.
|
|
201
|
-
* @param {(payload: string) => void} callback The event handler invoked when a NOTIFY message arrives.
|
|
202
|
-
* @returns {Future<() => Promise<void>, PostgresError>} A `Future` resolving to an async unsubscribe function.
|
|
64
|
+
* Subscribes `callback` to `channel` on a dedicated connection.
|
|
65
|
+
* Returns an unsubscribe function that issues `UNLISTEN` and releases the connection.
|
|
203
66
|
*
|
|
204
67
|
* @example
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
* const order = JSON.parse(payload);
|
|
208
|
-
* console.log(`New order received: ${order.id}`);
|
|
209
|
-
* });
|
|
210
|
-
*
|
|
211
|
-
* // When the subscription is no longer needed (e.g., during teardown or server stop):
|
|
212
|
-
* await unlisten(); // The socket cleanly issues UNLISTEN and returns to the pool of free connections.
|
|
213
|
-
*/
|
|
214
|
-
listen(channel: string, callback: (payload: string) => void): Future<() => Promise<void>, PostgresError>;
|
|
215
|
-
/**
|
|
216
|
-
* Number of available (idle) connections in the pool.
|
|
68
|
+
* const unlisten = await pool.listen('order_created', payload => console.log(payload))
|
|
69
|
+
* await unlisten()
|
|
217
70
|
*/
|
|
71
|
+
listen(channel: string, callback: (payload: string) => void): Future<() => Future<void, PostgresError>, PostgresError>;
|
|
72
|
+
/** Number of idle connections. */
|
|
218
73
|
get size(): number;
|
|
219
|
-
/**
|
|
220
|
-
* Total number of connections currently managed by the pool
|
|
221
|
-
* (available + in use).
|
|
222
|
-
*/
|
|
74
|
+
/** Total connections managed (idle + in use). */
|
|
223
75
|
get total(): number;
|
|
224
76
|
/**
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* All pending `acquire()` calls will be rejected with an error.
|
|
228
|
-
* The pool cannot be used after calling `close()`.
|
|
229
|
-
*
|
|
230
|
-
* @example
|
|
231
|
-
* ```ts
|
|
232
|
-
* pool.close()
|
|
233
|
-
* ```
|
|
77
|
+
* Closes idle connections and rejects pending `acquire()` calls. Not usable afterward.
|
|
234
78
|
*/
|
|
235
|
-
close(): void
|
|
79
|
+
close(): Future<void, PostgresError>;
|
|
236
80
|
}
|
|
237
|
-
export {};
|
|
238
81
|
//# sourceMappingURL=pool.d.ts.map
|
package/dist/pool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EAAS,MAAM,EAAM,MAAM,eAAe,CAAC;AAClD,OAAO,EAAiB,aAAa,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAc,iBAAiB,EAAE,GAAG,EAAU,MAAM,SAAS,CAAC;AAGrE;;;;;;;;GAQG;AACH,qBAAa,IAAI;IACb,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,MAAM,CAAI;IAClB,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,SAAS,CAAO;gBAEZ,MAAM,EAAE,iBAAiB;IAOrC;;;OAGG;IACH,OAAO;IA2BP;;;;;OAKG;IACH,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC;IAUnD,wFAAwF;IACxF,OAAO,CAAC,IAAI,EAAE,UAAU;IAoBxB;;;;;;;OAOG;IACH,KAAK,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC;IAU7D;;;;;OAKG;IACH,KAAK,CAAC,CAAC,SAAS,GAAG,EAAE,SAAS,EAAE,oBAAoB,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE;IAuBpE,qEAAqE;IACrE,OAAO,CAAC,SAAS,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE;IAuBzD;;;;;OAKG;IACH,MAAM,CAAC,CAAC,SAAS,GAAG,EAAE,SAAS,EAAE,oBAAoB,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC;IAoCzF,2EAA2E;IAC3E,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,MAAW;IAQhD;;;;;;;OAOG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI;IAY3D,kCAAkC;IAClC,IAAI,IAAI,WAEP;IAGD,iDAAiD;IACjD,IAAI,KAAK,WAER;IAGD;;OAEG;IACH,KAAK;CAiBR"}
|