Pool.d.ts 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. import {PoolConnection as PromisePoolConnection} from '../../../promise';
  7. declare namespace Pool {
  8. export interface PoolOptions extends Connection.ConnectionOptions {
  9. /**
  10. * The milliseconds before a timeout occurs during the connection acquisition. This is slightly different from connectTimeout,
  11. * because acquiring a pool connection does not always involve making a connection. (Default: 10 seconds)
  12. */
  13. acquireTimeout?: number;
  14. /**
  15. * Determines the pool's action when no connections are available and the limit has been reached. If true, the pool will queue
  16. * the connection request and call it when one becomes available. If false, the pool will immediately call back with an error.
  17. * (Default: true)
  18. */
  19. waitForConnections?: boolean;
  20. /**
  21. * The maximum number of connections to create at once. (Default: 10)
  22. */
  23. connectionLimit?: number;
  24. /**
  25. * The minimum number of idle connections. (Default: 10)
  26. */
  27. maxIdle?: number;
  28. /**
  29. * The idle connections timeout, in milliseconds. (Default: 60000)
  30. */
  31. idleTimeout?: number;
  32. /**
  33. * The maximum number of connection requests the pool will queue before returning an error from getConnection. If set to 0, there
  34. * is no limit to the number of queued connection requests. (Default: 0)
  35. */
  36. queueLimit?: number;
  37. /**
  38. * Enable keep-alive on the socket. (Default: true)
  39. */
  40. enableKeepAlive?: boolean;
  41. /**
  42. * If keep-alive is enabled users can supply an initial delay. (Default: 0)
  43. */
  44. keepAliveInitialDelay?: number;
  45. }
  46. }
  47. declare class Pool extends EventEmitter {
  48. config: Pool.PoolOptions;
  49. getConnection(callback: (err: NodeJS.ErrnoException | null, connection: PoolConnection) => any): void;
  50. query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(sql: string, callback?: (err: Query.QueryError | null, result: T, fields: FieldPacket[]) => any): Query;
  51. 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;
  52. query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(options: Query.QueryOptions, callback?: (err: Query.QueryError | null, result: T, fields?: FieldPacket[]) => any): Query;
  53. 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;
  54. execute<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(sql: string, callback?: (err: Query.QueryError | null, result: T, fields: FieldPacket[]) => any): Query;
  55. execute<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;
  56. execute<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(options: Query.QueryOptions, callback?: (err: Query.QueryError | null, result: T, fields?: FieldPacket[]) => any): Query;
  57. execute<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;
  58. end(callback?: (err: NodeJS.ErrnoException | null, ...args: any[]) => any): void;
  59. on(event: string, listener: Function): this;
  60. on(event: 'connection', listener: (connection: PoolConnection) => any): this;
  61. promise(promiseImpl?: PromiseConstructor): PromisePoolConnection;
  62. }
  63. export = Pool;