aboutsummaryrefslogtreecommitdiff
path: root/node_modules/mysql2/typings/mysql/lib/PoolCluster.d.ts
blob: 92909abd4cc751c2c94c030578a4100ae26c908d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

import Connection = require('./Connection');
import PoolConnection = require('./PoolConnection');
import {EventEmitter} from 'events';

declare namespace PoolCluster {

    export interface PoolClusterOptions {
        /**
         * If true, PoolCluster will attempt to reconnect when connection fails. (Default: true)
         */
        canRetry?: boolean;

        /**
         * If connection fails, node's errorCount increases. When errorCount is greater than removeNodeErrorCount,
         * remove a node in the PoolCluster. (Default: 5)
         */
        removeNodeErrorCount?: number;

        /**
         * If connection fails, specifies the number of milliseconds before another connection attempt will be made.
         * If set to 0, then node will be removed instead and never re-used. (Default: 0)
         */
        restoreNodeTimeout?: number;

        /**
         * The default selector. (Default: RR)
         * RR: Select one alternately. (Round-Robin)
         * RANDOM: Select the node by random function.
         * ORDER: Select the first node available unconditionally.
         */
        defaultSelector?: string;
    }
}

declare class PoolCluster extends EventEmitter {

    config: PoolCluster.PoolClusterOptions;

    add(config: PoolCluster.PoolClusterOptions): void;
    add(group: string, config: PoolCluster.PoolClusterOptions): void;

    end(): void;

    getConnection(callback: (err: NodeJS.ErrnoException | null, connection: PoolConnection) => void): void;
    getConnection(group: string, callback: (err: NodeJS.ErrnoException | null, connection: PoolConnection) => void): void;
    getConnection(group: string, selector: string, callback: (err: NodeJS.ErrnoException | null, connection: PoolConnection) => void): void;

    of(pattern: string, selector?: string): PoolCluster;

    on(event: string, listener: Function): this;
    on(event: 'remove', listener: (nodeId: number) => void): this;
    on(event: 'connection', listener: (connection: PoolConnection) => void): this;
}

export = PoolCluster;