1 | import {
|
2 | RowDataPacket,
|
3 | OkPacket,
|
4 | ResultSetHeader,
|
5 | FieldPacket,
|
6 | QueryOptions,
|
7 | ConnectionOptions,
|
8 | PoolOptions,
|
9 | Pool as CorePool
|
10 | } from './index';
|
11 |
|
12 | import { EventEmitter } from 'events';
|
13 | export * from './index';
|
14 |
|
15 | export interface Connection extends EventEmitter {
|
16 | config: ConnectionOptions;
|
17 | threadId: number;
|
18 |
|
19 | connect(): Promise<void>;
|
20 | ping(): Promise<void>;
|
21 |
|
22 | beginTransaction(): Promise<void>;
|
23 | commit(): Promise<void>;
|
24 | rollback(): Promise<void>;
|
25 |
|
26 | changeUser(options: ConnectionOptions): Promise<void>;
|
27 |
|
28 | query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(
|
29 | sql: string
|
30 | ): Promise<[T, FieldPacket[]]>;
|
31 | query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(
|
32 | sql: string,
|
33 | values: any | any[] | { [param: string]: any }
|
34 | ): Promise<[T, FieldPacket[]]>;
|
35 | query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(
|
36 | options: QueryOptions
|
37 | ): Promise<[T, FieldPacket[]]>;
|
38 | query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(
|
39 | options: QueryOptions,
|
40 | values: any | any[] | { [param: string]: any }
|
41 | ): Promise<[T, FieldPacket[]]>;
|
42 |
|
43 | execute<
|
44 | T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader
|
45 | >(
|
46 | sql: string
|
47 | ): Promise<[T, FieldPacket[]]>;
|
48 | execute<
|
49 | T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader
|
50 | >(
|
51 | sql: string,
|
52 | values: any | any[] | { [param: string]: any }
|
53 | ): Promise<[T, FieldPacket[]]>;
|
54 | execute<
|
55 | T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader
|
56 | >(
|
57 | options: QueryOptions
|
58 | ): Promise<[T, FieldPacket[]]>;
|
59 | execute<
|
60 | T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader
|
61 | >(
|
62 | options: QueryOptions,
|
63 | values: any | any[] | { [param: string]: any }
|
64 | ): Promise<[T, FieldPacket[]]>;
|
65 |
|
66 | prepare(options: string | QueryOptions): Promise<PreparedStatementInfo>;
|
67 | unprepare(sql: string | QueryOptions): void;
|
68 |
|
69 | end(options?: any): Promise<void>;
|
70 |
|
71 | destroy(): void;
|
72 |
|
73 | pause(): void;
|
74 |
|
75 | resume(): void;
|
76 |
|
77 | escape(value: any): string;
|
78 |
|
79 | escapeId(value: string): string;
|
80 | escapeId(values: string[]): string;
|
81 |
|
82 | format(sql: string, values?: any | any[] | { [param: string]: any }): string;
|
83 | }
|
84 |
|
85 | export interface PoolConnection extends Connection {
|
86 | connection: Connection;
|
87 | release(): void;
|
88 | }
|
89 |
|
90 | export interface Pool extends EventEmitter {
|
91 | query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(
|
92 | sql: string
|
93 | ): Promise<[T, FieldPacket[]]>;
|
94 | query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(
|
95 | sql: string,
|
96 | values: any | any[] | { [param: string]: any }
|
97 | ): Promise<[T, FieldPacket[]]>;
|
98 | query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(
|
99 | options: QueryOptions
|
100 | ): Promise<[T, FieldPacket[]]>;
|
101 | query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(
|
102 | options: QueryOptions,
|
103 | values: any | any[] | { [param: string]: any }
|
104 | ): Promise<[T, FieldPacket[]]>;
|
105 |
|
106 | execute<
|
107 | T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader
|
108 | >(
|
109 | sql: string
|
110 | ): Promise<[T, FieldPacket[]]>;
|
111 | execute<
|
112 | T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader
|
113 | >(
|
114 | sql: string,
|
115 | values: any | any[] | { [param: string]: any }
|
116 | ): Promise<[T, FieldPacket[]]>;
|
117 | execute<
|
118 | T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader
|
119 | >(
|
120 | options: QueryOptions
|
121 | ): Promise<[T, FieldPacket[]]>;
|
122 | execute<
|
123 | T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader
|
124 | >(
|
125 | options: QueryOptions,
|
126 | values: any | any[] | { [param: string]: any }
|
127 | ): Promise<[T, FieldPacket[]]>;
|
128 |
|
129 | getConnection(): Promise<PoolConnection>;
|
130 | on(event: 'connection', listener: (connection: PoolConnection) => any): this;
|
131 | on(event: 'acquire', listener: (connection: PoolConnection) => any): this;
|
132 | on(event: 'release', listener: (connection: PoolConnection) => any): this;
|
133 | on(event: 'enqueue', listener: () => any): this;
|
134 | end(): Promise<void>;
|
135 |
|
136 | escape(value: any): string;
|
137 | escapeId(value: string): string;
|
138 | escapeId(values: string[]): string;
|
139 | format(sql: string, values?: any | any[] | { [param: string]: any }): string;
|
140 |
|
141 | pool: CorePool;
|
142 | }
|
143 |
|
144 | export function createConnection(connectionUri: string): Promise<Connection>;
|
145 | export function createConnection(
|
146 | config: ConnectionOptions
|
147 | ): Promise<Connection>;
|
148 | export function createPool(connectionUri: string): Pool;
|
149 | export function createPool(config: PoolOptions): Pool;
|
150 |
|
151 | export interface PreparedStatementInfo {
|
152 | close(): Promise<void>;
|
153 | execute(parameters: any[]): Promise<[RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader, FieldPacket[]]>;
|
154 | }
|
155 |
|
156 | export interface PromisePoolConnection extends Connection {
|
157 | destroy(): any;
|
158 | }
|