-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathindex.d.ts
144 lines (88 loc) · 4.44 KB
/
index.d.ts
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import * as mysql from 'mysql';
import Bluebird from 'bluebird';
export function createConnection(connectionUri: string | ConnectionConfig): Bluebird<Connection>;
export function createPool(config: PoolConfig | string): Bluebird<Pool>;
export function createPoolCluster(config: mysql.PoolClusterConfig): Bluebird<PoolCluster>;
export { Types, escape, escapeId, format, raw, ConnectionOptions, PoolClusterConfig, MysqlError } from 'mysql';
export type mysqlModule = typeof mysql;
export type ArgumentsArray<T> = [data: T[], fields: mysql.FieldInfo[], query: Query<T>];
export interface ConnectionConfig extends mysql.ConnectionConfig {
mysqlWrapper?: (mysql: mysqlModule, callback?: (err: Error | null, success?: mysqlModule) => void) => mysqlModule | Promise<mysqlModule> | void;
returnArgumentsArray?: boolean;
reconnect?: boolean;
}
export interface PoolConfig extends mysql.PoolConfig {
mysqlWrapper?: (mysql: mysqlModule, callback: (err: Error | null, success?: mysqlModule) => void) => mysqlModule | Promise<mysqlModule> | void;
returnArgumentsArray?: boolean;
reconnect?: boolean;
}
export interface QueryFunction {
<T = any>(query: mysql.Query | string | mysql.QueryOptions): Bluebird<T>;
<T = any>(options: string, values?: any): Bluebird<T>;
}
export interface Query<T> extends mysql.Query {
on(ev: 'result', callback: (row: T, index: number) => void): mysql.Query;
on(ev: 'error', callback: (err: mysql.MysqlError) => void): mysql.Query;
on(ev: 'fields', callback: (fields: mysql.FieldInfo[], index: number) => void): mysql.Query;
on<T = any>(ev: 'packet', callback: (packet: T) => void): mysql.Query;
on(ev: 'end', callback: () => void): mysql.Query;
}
export class Connection {
constructor(config: string | ConnectionConfig, _connection?: Connection);
query: QueryFunction;
beginTransaction(options?: mysql.QueryOptions): Bluebird<void>;
commit(options?: mysql.QueryOptions): Bluebird<void>;
rollback(options?: mysql.QueryOptions): Bluebird<void>;
changeUser(options?: mysql.ConnectionOptions): Bluebird<void>;
ping(options?: mysql.QueryOptions): Bluebird<void>;
queryStream<T = any>(options: string, values?: any): Query<T>;
statistics(options?: mysql.QueryOptions): Bluebird<void>;
end(options?: mysql.QueryOptions): Bluebird<void>;
destroy(): void;
pause(): void;
resume(): void;
escape(value: any, stringifyObjects?: boolean, timeZone?: string): string;
escapeId(value: string, forbidQualified?: boolean): string;
format(sql: string, values: any[], stringifyObjects?: boolean, timeZone?: string): string;
on(ev: 'error', callback: (err: mysql.MysqlError) => void): void;
on(ev: 'end', callback: () => void): void;
}
export class PoolConnection extends Connection {
constructor(config: ConnectionConfig, _connection?: mysql.Connection);
release(): any;
}
export class Pool {
constructor(config: ConnectionConfig, _pool?: mysql.Pool);
getConnection(): Bluebird<PoolConnection>;
query: QueryFunction;
end(options?: mysql.QueryOptions): Bluebird<void>;
release(options?: mysql.QueryOptions): Bluebird<void>;
escape(value: any, stringifyObjects?: boolean, timeZone?: string): string;
escapeId(value: string, forbidQualified?: boolean): string;
on(ev: 'connection' | 'acquire' | 'release', callback: (connection: mysql.PoolConnection) => void): mysql.Pool;
on(ev: 'error', callback: (err: mysql.MysqlError) => void): mysql.Pool;
on(ev: 'enqueue', callback: (err?: mysql.MysqlError) => void): mysql.Pool;
on<T = any>(ev: string, callback: (...args: T[]) => void): mysql.Pool;
}
export class PoolCluster {
constructor(config: mysql.PoolClusterConfig);
config: mysql.PoolClusterConfig;
add(config: PoolConfig): void;
add(id: string, config: PoolConfig): void;
end(): Bluebird<void>;
of(pattern: string, selector?: string): Pool;
of(pattern: undefined | null | false, selector: string): Pool;
/**
* remove all pools which match pattern
*/
remove(pattern: string): void;
getConnection(pattern?: string, selector?: string): Bluebird<PoolConnection>;
/**
* Set handler to be run on a certain event.
*/
on<T = any>(ev: string, callback: (...args: T[]) => void): PoolCluster;
/**
* Set handler to be run when a node is removed or goes offline.
*/
on(ev: 'remove' | 'offline', callback: (nodeId: string) => void): PoolCluster;
}