UNPKG

2.31 kBTypeScriptView Raw
1import { EventEmitter } from 'events';
2import { PrepareStatementInfo } from './protocol/sequences/Prepare.js';
3import { ConnectionOptions } from './Connection.js';
4import { PoolConnection } from './PoolConnection.js';
5import {
6 Pool as PromisePool,
7 PoolConnection as PromisePoolConnection,
8} from '../../../promise.js';
9import { QueryableBase } from './protocol/sequences/QueryableBase.js';
10import { ExecutableBase } from './protocol/sequences/ExecutableBase.js';
11
12export interface PoolOptions extends ConnectionOptions {
13 /**
14 * Determines the pool's action when no connections are available and the limit has been reached. If true, the pool will queue
15 * the connection request and call it when one becomes available. If false, the pool will immediately call back with an error.
16 * (Default: true)
17 */
18 waitForConnections?: boolean;
19
20 /**
21 * The maximum number of connections to create at once. (Default: 10)
22 */
23 connectionLimit?: number;
24
25 /**
26 * The maximum number of idle connections. (Default: same as `connectionLimit`)
27 */
28 maxIdle?: number;
29
30 /**
31 * The idle connections timeout, in milliseconds. (Default: 60000)
32 */
33 idleTimeout?: number;
34
35 /**
36 * The maximum number of connection requests the pool will queue before returning an error from getConnection. If set to 0, there
37 * is no limit to the number of queued connection requests. (Default: 0)
38 */
39 queueLimit?: number;
40}
41
42declare class Pool extends QueryableBase(ExecutableBase(EventEmitter)) {
43 getConnection(
44 callback: (
45 err: NodeJS.ErrnoException | null,
46 connection: PoolConnection,
47 ) => any,
48 ): void;
49
50 releaseConnection(connection: PoolConnection | PromisePoolConnection): void;
51
52 end(
53 callback?: (err: NodeJS.ErrnoException | null, ...args: any[]) => any,
54 ): void;
55
56 on(event: string, listener: (...args: any[]) => void): this;
57 on(event: 'connection', listener: (connection: PoolConnection) => any): this;
58 on(event: 'acquire', listener: (connection: PoolConnection) => any): this;
59 on(event: 'release', listener: (connection: PoolConnection) => any): this;
60 on(event: 'enqueue', listener: () => any): this;
61
62 unprepare(sql: string): PrepareStatementInfo;
63
64 promise(promiseImpl?: PromiseConstructor): PromisePool;
65
66 config: PoolOptions;
67}
68
69export { Pool };