Pool.d.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import Query = require('./protocol/sequences/Query');
  2. import {OkPacket, RowDataPacket, FieldPacket, ResultSetHeader} from './protocol/packets/index';
  3. import Connection = require('./Connection');
  4. import PoolConnection = require('./PoolConnection');
  5. import {EventEmitter} from 'events';
  6. declare namespace Pool {
  7. export interface PoolOptions extends Connection.ConnectionOptions {
  8. /**
  9. * The milliseconds before a timeout occurs during the connection acquisition. This is slightly different from connectTimeout,
  10. * because acquiring a pool connection does not always involve making a connection. (Default: 10 seconds)
  11. */
  12. acquireTimeout?: number;
  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. * The maximum number of connections to create at once. (Default: 10)
  21. */
  22. connectionLimit?: number;
  23. /**
  24. * The maximum number of connection requests the pool will queue before returning an error from getConnection. If set to 0, there
  25. * is no limit to the number of queued connection requests. (Default: 0)
  26. */
  27. queueLimit?: number;
  28. /**
  29. * Enable keep-alive on the socket. It's disabled by default, but the
  30. * user can enable it and supply an initial delay.
  31. */
  32. enableKeepAlive?: true;
  33. /**
  34. * If keep-alive is enabled users can supply an initial delay.
  35. */
  36. keepAliveInitialDelay?: number;
  37. }
  38. }
  39. declare class Pool extends EventEmitter {
  40. config: Pool.PoolOptions;
  41. getConnection(callback: (err: NodeJS.ErrnoException, connection: PoolConnection) => any): void;
  42. query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(sql: string, callback?: (err: Query.QueryError | null, result: T, fields: FieldPacket[]) => any): Query;
  43. query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(sql: string, values: any | any[] | { [param: string]: any }, callback?: (err: Query.QueryError | null, result: T, fields: FieldPacket[]) => any): Query;
  44. query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(options: Query.QueryOptions, callback?: (err: Query.QueryError | null, result: T, fields?: FieldPacket[]) => any): Query;
  45. query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(options: Query.QueryOptions, values: any | any[] | { [param: string]: any }, callback?: (err: Query.QueryError | null, result: T, fields: FieldPacket[]) => any): Query;
  46. end(callback?: (err: NodeJS.ErrnoException | null, ...args: any[]) => any): void;
  47. on(event: string, listener: Function): this;
  48. on(event: 'connection', listener: (connection: PoolConnection) => any): this;
  49. }
  50. export = Pool;