Pool.d.ts 2.3 KB

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