-
-
Notifications
You must be signed in to change notification settings - Fork 619
/
promise.d.ts
131 lines (94 loc) · 3.33 KB
/
promise.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
import { EventEmitter } from 'events';
import {
RowDataPacket,
OkPacket,
ResultSetHeader,
FieldPacket,
QueryOptions,
ConnectionOptions,
PoolOptions,
PoolClusterOptions,
Pool as CorePool,
} from './index.js';
import { ExecutableBase as ExecutableBaseClass } from './typings/mysql/lib/protocol/sequences/promise/ExecutableBase.js';
import { QueryableBase as QueryableBaseClass } from './typings/mysql/lib/protocol/sequences/promise/QueryableBase.js';
export * from './index.js';
// Expose class interfaces
declare class QueryableAndExecutableBase extends QueryableBaseClass(
ExecutableBaseClass(EventEmitter),
) {}
export interface PreparedStatementInfo {
close(): Promise<void>;
execute(
parameters: any | any[] | { [param: string]: any },
): Promise<
[
(
| RowDataPacket[][]
| RowDataPacket[]
| OkPacket
| OkPacket[]
| ResultSetHeader
),
FieldPacket[],
]
>;
}
export interface Connection extends QueryableAndExecutableBase {
config: ConnectionOptions;
threadId: number;
connect(): Promise<void>;
ping(): Promise<void>;
beginTransaction(): Promise<void>;
commit(): Promise<void>;
rollback(): Promise<void>;
changeUser(options: ConnectionOptions): Promise<void>;
prepare(options: string | QueryOptions): Promise<PreparedStatementInfo>;
unprepare(sql: string | QueryOptions): void;
end(options?: any): Promise<void>;
destroy(): void;
pause(): void;
resume(): void;
escape(value: any): string;
escapeId(value: string): string;
escapeId(values: string[]): string;
format(sql: string, values?: any | any[] | { [param: string]: any }): string;
}
export interface PoolConnection extends Connection {
release(): void;
connection: Connection;
}
export interface Pool extends Connection {
getConnection(): Promise<PoolConnection>;
releaseConnection(connection: PoolConnection): void;
on(event: 'connection', listener: (connection: PoolConnection) => any): this;
on(event: 'acquire', listener: (connection: PoolConnection) => any): this;
on(event: 'release', listener: (connection: PoolConnection) => any): this;
on(event: 'enqueue', listener: () => any): this;
end(): Promise<void>;
pool: CorePool;
}
export interface PoolNamespace extends QueryableAndExecutableBase {
getConnection(): Promise<PoolConnection>;
}
export interface PoolCluster extends EventEmitter {
config: PoolClusterOptions;
add(config: PoolOptions): void;
add(group: string, connectionUri: string): void;
add(group: string, config: PoolOptions): void;
end(): Promise<void>;
getConnection(): Promise<PoolConnection>;
getConnection(group: string): Promise<PoolConnection>;
getConnection(group: string, selector: string): Promise<PoolConnection>;
of(pattern: string, selector?: string): PoolNamespace;
on(event: string, listener: (...args: any[]) => void): this;
on(event: 'remove', listener: (nodeId: number) => void): this;
on(event: 'warn', listener: (err: Error) => void): this;
}
export function createConnection(connectionUri: string): Promise<Connection>;
export function createConnection(
config: ConnectionOptions,
): Promise<Connection>;
export function createPool(connectionUri: string): Pool;
export function createPool(config: PoolOptions): Pool;
export function createPoolCluster(config?: PoolClusterOptions): PoolCluster;