mysql2 2.2.1 → 2.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Changelog.md CHANGED
@@ -1,5 +1,17 @@
1
+ 2.2.5 ( 21/09/2020 )
2
+ - typings: add ResultSetHeader #1213
3
+
4
+ 2.2.4 ( 21/09/2020 )
5
+ - use bundled types/mysql instead of dependency #1211
6
+
7
+ 2.2.3 ( 21/09/2020 )
8
+ - use github:types/mysql as base for types #1208
9
+
10
+ 2.2.2 ( 19/09/2020 )
11
+ - Add the authPlugins types to ConnectionOptions #1206
12
+
1
13
  2.2.1 ( 18/09/2020 )
2
- - update package.json files entry tu include
14
+ - update package.json files entry to include
3
15
  type definition files #1205
4
16
 
5
17
  2.2.0 ( 18/09/2020 )
package/index.d.ts CHANGED
@@ -4,8 +4,8 @@ import {
4
4
  PoolConnection as PromisePoolConnection
5
5
  } from './promise';
6
6
 
7
- import * as mysql from 'mysql';
8
- export * from 'mysql';
7
+ import * as mysql from './typings/mysql';
8
+ export * from './typings/mysql';
9
9
 
10
10
  export interface Connection extends mysql.Connection {
11
11
  execute<
@@ -14,6 +14,7 @@ export interface Connection extends mysql.Connection {
14
14
  | mysql.RowDataPacket[]
15
15
  | mysql.OkPacket
16
16
  | mysql.OkPacket[]
17
+ | mysql.ResultSetHeader
17
18
  >(
18
19
  sql: string,
19
20
  callback?: (
@@ -28,6 +29,7 @@ export interface Connection extends mysql.Connection {
28
29
  | mysql.RowDataPacket[]
29
30
  | mysql.OkPacket
30
31
  | mysql.OkPacket[]
32
+ | mysql.ResultSetHeader
31
33
  >(
32
34
  sql: string,
33
35
  values: any | any[] | { [param: string]: any },
@@ -43,6 +45,7 @@ export interface Connection extends mysql.Connection {
43
45
  | mysql.RowDataPacket[]
44
46
  | mysql.OkPacket
45
47
  | mysql.OkPacket[]
48
+ | mysql.ResultSetHeader
46
49
  >(
47
50
  options: mysql.QueryOptions,
48
51
  callback?: (
@@ -57,6 +60,7 @@ export interface Connection extends mysql.Connection {
57
60
  | mysql.RowDataPacket[]
58
61
  | mysql.OkPacket
59
62
  | mysql.OkPacket[]
63
+ | mysql.ResultSetHeader
60
64
  >(
61
65
  options: mysql.QueryOptions,
62
66
  values: any | any[] | { [param: string]: any },
@@ -81,6 +85,7 @@ export interface Pool extends mysql.Connection {
81
85
  | mysql.RowDataPacket[]
82
86
  | mysql.OkPacket
83
87
  | mysql.OkPacket[]
88
+ | mysql.ResultSetHeader
84
89
  >(
85
90
  sql: string,
86
91
  callback?: (
@@ -95,6 +100,7 @@ export interface Pool extends mysql.Connection {
95
100
  | mysql.RowDataPacket[]
96
101
  | mysql.OkPacket
97
102
  | mysql.OkPacket[]
103
+ | mysql.ResultSetHeader
98
104
  >(
99
105
  sql: string,
100
106
  values: any | any[] | { [param: string]: any },
@@ -110,6 +116,7 @@ export interface Pool extends mysql.Connection {
110
116
  | mysql.RowDataPacket[]
111
117
  | mysql.OkPacket
112
118
  | mysql.OkPacket[]
119
+ | mysql.ResultSetHeader
113
120
  >(
114
121
  options: mysql.QueryOptions,
115
122
  callback?: (
@@ -124,6 +131,7 @@ export interface Pool extends mysql.Connection {
124
131
  | mysql.RowDataPacket[]
125
132
  | mysql.OkPacket
126
133
  | mysql.OkPacket[]
134
+ | mysql.ResultSetHeader
127
135
  >(
128
136
  options: mysql.QueryOptions,
129
137
  values: any | any[] | { [param: string]: any },
@@ -143,6 +151,10 @@ export interface Pool extends mysql.Connection {
143
151
  promise(promiseImpl?: PromiseConstructor): PromisePool;
144
152
  }
145
153
 
154
+ type authPlugins =
155
+ (pluginMetadata: { connection: Connection; command: string }) =>
156
+ (pluginData: Buffer) => Promise<string>;
157
+
146
158
  export interface ConnectionOptions extends mysql.ConnectionOptions {
147
159
  charsetNumber?: number;
148
160
  compress?: boolean;
@@ -162,6 +174,9 @@ export interface ConnectionOptions extends mysql.ConnectionOptions {
162
174
  Promise?: any;
163
175
  queueLimit?: number;
164
176
  waitForConnections?: boolean;
177
+ authPlugins?: {
178
+ [key: string]: authPlugins;
179
+ };
165
180
  }
166
181
 
167
182
  export interface PoolOptions extends mysql.PoolOptions, ConnectionOptions {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mysql2",
3
- "version": "2.2.1",
3
+ "version": "2.2.5",
4
4
  "description": "fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -36,6 +36,7 @@
36
36
  ],
37
37
  "files": [
38
38
  "lib",
39
+ "typings",
39
40
  "index.js",
40
41
  "index.d.ts",
41
42
  "promise.js",
@@ -51,7 +52,6 @@
51
52
  "author": "Andrey Sidorov <sidorares@yandex.ru>",
52
53
  "license": "MIT",
53
54
  "dependencies": {
54
- "@types/mysql": "^2.15.7",
55
55
  "denque": "^1.4.1",
56
56
  "generate-function": "^2.3.1",
57
57
  "iconv-lite": "^0.6.2",
package/promise.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  RowDataPacket,
3
3
  OkPacket,
4
+ ResultSetHeader,
4
5
  FieldPacket,
5
6
  QueryOptions,
6
7
  ConnectionOptions,
@@ -23,39 +24,39 @@ export interface Connection extends EventEmitter {
23
24
 
24
25
  changeUser(options: ConnectionOptions): Promise<void>;
25
26
 
26
- query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[]>(
27
+ query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(
27
28
  sql: string
28
29
  ): Promise<[T, FieldPacket[]]>;
29
- query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[]>(
30
+ query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(
30
31
  sql: string,
31
32
  values: any | any[] | { [param: string]: any }
32
33
  ): Promise<[T, FieldPacket[]]>;
33
- query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[]>(
34
+ query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(
34
35
  options: QueryOptions
35
36
  ): Promise<[T, FieldPacket[]]>;
36
- query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[]>(
37
+ query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(
37
38
  options: QueryOptions,
38
39
  values: any | any[] | { [param: string]: any }
39
40
  ): Promise<[T, FieldPacket[]]>;
40
41
 
41
42
  execute<
42
- T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[]
43
+ T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader
43
44
  >(
44
45
  sql: string
45
46
  ): Promise<[T, FieldPacket[]]>;
46
47
  execute<
47
- T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[]
48
+ T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader
48
49
  >(
49
50
  sql: string,
50
51
  values: any | any[] | { [param: string]: any }
51
52
  ): Promise<[T, FieldPacket[]]>;
52
53
  execute<
53
- T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[]
54
+ T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader
54
55
  >(
55
56
  options: QueryOptions
56
57
  ): Promise<[T, FieldPacket[]]>;
57
58
  execute<
58
- T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[]
59
+ T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader
59
60
  >(
60
61
  options: QueryOptions,
61
62
  values: any | any[] | { [param: string]: any }
@@ -84,39 +85,39 @@ export interface PoolConnection extends Connection {
84
85
  }
85
86
 
86
87
  export interface Pool extends EventEmitter {
87
- query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[]>(
88
+ query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(
88
89
  sql: string
89
90
  ): Promise<[T, FieldPacket[]]>;
90
- query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[]>(
91
+ query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(
91
92
  sql: string,
92
93
  values: any | any[] | { [param: string]: any }
93
94
  ): Promise<[T, FieldPacket[]]>;
94
- query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[]>(
95
+ query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(
95
96
  options: QueryOptions
96
97
  ): Promise<[T, FieldPacket[]]>;
97
- query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[]>(
98
+ query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(
98
99
  options: QueryOptions,
99
100
  values: any | any[] | { [param: string]: any }
100
101
  ): Promise<[T, FieldPacket[]]>;
101
102
 
102
103
  execute<
103
- T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[]
104
+ T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader
104
105
  >(
105
106
  sql: string
106
107
  ): Promise<[T, FieldPacket[]]>;
107
108
  execute<
108
- T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[]
109
+ T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader
109
110
  >(
110
111
  sql: string,
111
112
  values: any | any[] | { [param: string]: any }
112
113
  ): Promise<[T, FieldPacket[]]>;
113
114
  execute<
114
- T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[]
115
+ T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader
115
116
  >(
116
117
  options: QueryOptions
117
118
  ): Promise<[T, FieldPacket[]]>;
118
119
  execute<
119
- T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[]
120
+ T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader
120
121
  >(
121
122
  options: QueryOptions,
122
123
  values: any | any[] | { [param: string]: any }
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2016, Felix Frederick Becker
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,36 @@
1
+
2
+ import BaseConnection = require('./lib/Connection');
3
+ import {ConnectionOptions, SslOptions} from './lib/Connection';
4
+ import BasePoolConnection = require('./lib/PoolConnection');
5
+ import BasePool = require('./lib/Pool');
6
+ import {PoolOptions} from './lib/Pool';
7
+ import BasePoolCluster = require('./lib/PoolCluster');
8
+ import {PoolClusterOptions} from './lib/PoolCluster';
9
+ import BaseQuery = require('./lib/protocol/sequences/Query');
10
+ import {QueryOptions, StreamOptions, QueryError} from './lib/protocol/sequences/Query';
11
+
12
+ export function createConnection(connectionUri: string): Connection;
13
+ export function createConnection(config: BaseConnection.ConnectionOptions): Connection;
14
+ export function createPool(config: BasePool.PoolOptions): Pool;
15
+ export function createPoolCluster(config?: BasePoolCluster.PoolClusterOptions): PoolCluster;
16
+ export function escape(value: any): string;
17
+ export function format(sql: string): string;
18
+ export function format(sql: string, values: any[]): string;
19
+ export function format(sql: string, values: any): string;
20
+
21
+ export {
22
+ ConnectionOptions,
23
+ SslOptions,
24
+ PoolOptions,
25
+ PoolClusterOptions,
26
+ QueryOptions,
27
+ QueryError
28
+ };
29
+ export * from './lib/protocol/packets/index';
30
+
31
+ // Expose class interfaces
32
+ export interface Connection extends BaseConnection {}
33
+ export interface PoolConnection extends BasePoolConnection {}
34
+ export interface Pool extends BasePool {}
35
+ export interface PoolCluster extends BasePoolCluster {}
36
+ export interface Query extends BaseQuery {}
@@ -0,0 +1 @@
1
+ temporary workaround, see https://github.com/sidorares/node-mysql2/issues/1210
@@ -0,0 +1,237 @@
1
+
2
+ import Query = require('./protocol/sequences/Query');
3
+ import {OkPacket, FieldPacket, RowDataPacket, ResultSetHeader} from './protocol/packets/index';
4
+ import {EventEmitter} from 'events';
5
+
6
+ declare namespace Connection {
7
+
8
+ export interface ConnectionOptions {
9
+ /**
10
+ * The MySQL user to authenticate as
11
+ */
12
+ user?: string;
13
+
14
+ /**
15
+ * The password of that MySQL user
16
+ */
17
+ password?: string;
18
+
19
+ /**
20
+ * Name of the database to use for this connection
21
+ */
22
+ database?: string;
23
+
24
+ /**
25
+ * The charset for the connection. This is called 'collation' in the SQL-level of MySQL (like utf8_general_ci).
26
+ * If a SQL-level charset is specified (like utf8mb4) then the default collation for that charset is used.
27
+ * (Default: 'UTF8_GENERAL_CI')
28
+ */
29
+ charset?: string;
30
+
31
+ /**
32
+ * The hostname of the database you are connecting to. (Default: localhost)
33
+ */
34
+ host?: string;
35
+
36
+ /**
37
+ * The port number to connect to. (Default: 3306)
38
+ */
39
+ port?: number;
40
+
41
+ /**
42
+ * The source IP address to use for TCP connection
43
+ */
44
+ localAddress?: string;
45
+
46
+ /**
47
+ * The path to a unix domain socket to connect to. When used host and port are ignored
48
+ */
49
+ socketPath?: string;
50
+
51
+ /**
52
+ * The timezone used to store local dates. (Default: 'local')
53
+ */
54
+ timezone?: string | 'local';
55
+
56
+ /**
57
+ * The milliseconds before a timeout occurs during the initial connection to the MySQL server. (Default: 10 seconds)
58
+ */
59
+ connectTimeout?: number;
60
+
61
+ /**
62
+ * Stringify objects instead of converting to values. (Default: 'false')
63
+ */
64
+ stringifyObjects?: boolean;
65
+
66
+ /**
67
+ * Allow connecting to MySQL instances that ask for the old (insecure) authentication method. (Default: false)
68
+ */
69
+ insecureAuth?: boolean;
70
+
71
+ /**
72
+ * Determines if column values should be converted to native JavaScript types. It is not recommended (and may go away / change in the future)
73
+ * to disable type casting, but you can currently do so on either the connection or query level. (Default: true)
74
+ *
75
+ * You can also specify a function (field: any, next: () => void) => {} to do the type casting yourself.
76
+ *
77
+ * WARNING: YOU MUST INVOKE the parser using one of these three field functions in your custom typeCast callback. They can only be called once.
78
+ *
79
+ * field.string()
80
+ * field.buffer()
81
+ * field.geometry()
82
+ *
83
+ * are aliases for
84
+ *
85
+ * parser.parseLengthCodedString()
86
+ * parser.parseLengthCodedBuffer()
87
+ * parser.parseGeometryValue()
88
+ *
89
+ * You can find which field function you need to use by looking at: RowDataPacket.prototype._typeCast
90
+ */
91
+ typeCast?: boolean | ((field: any, next: () => void) => any);
92
+
93
+ /**
94
+ * A custom query format function
95
+ */
96
+ queryFormat?: (query: string, values: any) => void;
97
+
98
+ /**
99
+ * When dealing with big numbers (BIGINT and DECIMAL columns) in the database, you should enable this option
100
+ * (Default: false)
101
+ */
102
+ supportBigNumbers?: boolean;
103
+
104
+ /**
105
+ * Enabling both supportBigNumbers and bigNumberStrings forces big numbers (BIGINT and DECIMAL columns) to be
106
+ * always returned as JavaScript String objects (Default: false). Enabling supportBigNumbers but leaving
107
+ * bigNumberStrings disabled will return big numbers as String objects only when they cannot be accurately
108
+ * represented with [JavaScript Number objects] (http://ecma262-5.com/ELS5_HTML.htm#Section_8.5)
109
+ * (which happens when they exceed the [-2^53, +2^53] range), otherwise they will be returned as Number objects.
110
+ * This option is ignored if supportBigNumbers is disabled.
111
+ */
112
+ bigNumberStrings?: boolean;
113
+
114
+ /**
115
+ * Force date types (TIMESTAMP, DATETIME, DATE) to be returned as strings rather then inflated into JavaScript Date
116
+ * objects. Can be true/false or an array of type names to keep as strings.
117
+ *
118
+ * (Default: false)
119
+ */
120
+ dateStrings?: boolean | Array<'TIMESTAMP' | 'DATETIME' | 'DATE'>;
121
+
122
+ /**
123
+ * This will print all incoming and outgoing packets on stdout.
124
+ * You can also restrict debugging to packet types by passing an array of types (strings) to debug;
125
+ *
126
+ * (Default: false)
127
+ */
128
+ debug?: any;
129
+
130
+ /**
131
+ * Generates stack traces on Error to include call site of library entrance ('long stack traces'). Slight
132
+ * performance penalty for most calls. (Default: true)
133
+ */
134
+ trace?: boolean;
135
+
136
+ /**
137
+ * Allow multiple mysql statements per query. Be careful with this, it exposes you to SQL injection attacks. (Default: false)
138
+ */
139
+ multipleStatements?: boolean;
140
+
141
+ /**
142
+ * List of connection flags to use other than the default ones. It is also possible to blacklist default ones
143
+ */
144
+ flags?: Array<string>;
145
+
146
+ /**
147
+ * object with ssl parameters or a string containing name of ssl profile
148
+ */
149
+ ssl?: string | SslOptions;
150
+ }
151
+
152
+ export interface SslOptions {
153
+ /**
154
+ * A string or buffer holding the PFX or PKCS12 encoded private key, certificate and CA certificates
155
+ */
156
+ pfx?: string;
157
+
158
+ /**
159
+ * A string holding the PEM encoded private key
160
+ */
161
+ key?: string;
162
+
163
+ /**
164
+ * A string of passphrase for the private key or pfx
165
+ */
166
+ passphrase?: string;
167
+
168
+ /**
169
+ * A string holding the PEM encoded certificate
170
+ */
171
+ cert?: string;
172
+
173
+ /**
174
+ * Either a string or list of strings of PEM encoded CA certificates to trust.
175
+ */
176
+ ca?: string | string[];
177
+
178
+ /**
179
+ * Either a string or list of strings of PEM encoded CRLs (Certificate Revocation List)
180
+ */
181
+ crl?: string | string[];
182
+
183
+ /**
184
+ * A string describing the ciphers to use or exclude
185
+ */
186
+ ciphers?: string;
187
+
188
+ /**
189
+ * You can also connect to a MySQL server without properly providing the appropriate CA to trust. You should not do this.
190
+ */
191
+ rejectUnauthorized?: boolean;
192
+ }
193
+ }
194
+
195
+ declare class Connection extends EventEmitter {
196
+
197
+ config: Connection.ConnectionOptions;
198
+ threadId: number;
199
+
200
+ static createQuery<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(sql: string, callback?: (err: Query.QueryError | null, result: T, fields: FieldPacket[]) => any): Query;
201
+ static createQuery<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;
202
+
203
+ beginTransaction(callback: (err: Query.QueryError | null) => void): void;
204
+
205
+ connect(callback?: (err: Query.QueryError | null) => void): void;
206
+
207
+ commit(callback?: (err: Query.QueryError | null) => void): void;
208
+
209
+ changeUser(options: Connection.ConnectionOptions, callback?: (err: Query.QueryError | null) => void): void;
210
+
211
+ query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(sql: string, callback?: (err: Query.QueryError | null, result: T, fields: FieldPacket[]) => any): Query;
212
+ 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;
213
+ query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(options: Query.QueryOptions, callback?: (err: Query.QueryError | null, result: T, fields?: FieldPacket[]) => any): Query;
214
+ 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;
215
+
216
+ end(callback?: (err: Query.QueryError | null) => void): void;
217
+ end(options: any, callback?: (err: Query.QueryError | null) => void): void;
218
+
219
+ destroy(): void;
220
+
221
+ pause(): void;
222
+
223
+ resume(): void;
224
+
225
+ escape(value: any): string;
226
+
227
+ escapeId(value: string): string;
228
+ escapeId(values: string[]): string;
229
+
230
+ format(sql: string, values?: any | any[] | { [param: string]: any }): string;
231
+
232
+ on(event: string, listener: Function): this;
233
+
234
+ rollback(callback: () => void): void;
235
+ }
236
+
237
+ export = Connection;
@@ -0,0 +1,65 @@
1
+
2
+ import Query = require('./protocol/sequences/Query');
3
+ import {OkPacket, RowDataPacket, FieldPacket, ResultSetHeader} from './protocol/packets/index';
4
+ import Connection = require('./Connection');
5
+ import PoolConnection = require('./PoolConnection');
6
+ import {EventEmitter} from 'events';
7
+
8
+ declare namespace Pool {
9
+
10
+ export interface PoolOptions extends Connection.ConnectionOptions {
11
+ /**
12
+ * The milliseconds before a timeout occurs during the connection acquisition. This is slightly different from connectTimeout,
13
+ * because acquiring a pool connection does not always involve making a connection. (Default: 10 seconds)
14
+ */
15
+ acquireTimeout?: number;
16
+
17
+ /**
18
+ * Determines the pool's action when no connections are available and the limit has been reached. If true, the pool will queue
19
+ * the connection request and call it when one becomes available. If false, the pool will immediately call back with an error.
20
+ * (Default: true)
21
+ */
22
+ waitForConnections?: boolean;
23
+
24
+ /**
25
+ * The maximum number of connections to create at once. (Default: 10)
26
+ */
27
+ connectionLimit?: number;
28
+
29
+ /**
30
+ * The maximum number of connection requests the pool will queue before returning an error from getConnection. If set to 0, there
31
+ * is no limit to the number of queued connection requests. (Default: 0)
32
+ */
33
+ queueLimit?: number;
34
+
35
+ /**
36
+ * Enable keep-alive on the socket. It's disabled by default, but the
37
+ * user can enable it and supply an initial delay.
38
+ */
39
+ enableKeepAlive?: true;
40
+
41
+ /**
42
+ * If keep-alive is enabled users can supply an initial delay.
43
+ */
44
+ keepAliveInitialDelay?: number;
45
+ }
46
+ }
47
+
48
+ declare class Pool extends EventEmitter {
49
+
50
+ config: Pool.PoolOptions;
51
+
52
+ getConnection(callback: (err: NodeJS.ErrnoException, connection: PoolConnection) => any): void;
53
+
54
+ query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(sql: string, callback?: (err: Query.QueryError | null, result: T, fields: FieldPacket[]) => any): Query;
55
+ 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;
56
+ query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(options: Query.QueryOptions, callback?: (err: Query.QueryError | null, result: T, fields?: FieldPacket[]) => any): Query;
57
+ 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;
58
+
59
+ end(callback?: (err: NodeJS.ErrnoException | null, ...args: any[]) => any): void;
60
+
61
+ on(event: string, listener: Function): this;
62
+ on(event: 'connection', listener: (connection: PoolConnection) => any): this;
63
+ }
64
+
65
+ export = Pool;
@@ -0,0 +1,56 @@
1
+
2
+ import Connection = require('./Connection');
3
+ import PoolConnection = require('./PoolConnection');
4
+ import {EventEmitter} from 'events';
5
+
6
+ declare namespace PoolCluster {
7
+
8
+ export interface PoolClusterOptions {
9
+ /**
10
+ * If true, PoolCluster will attempt to reconnect when connection fails. (Default: true)
11
+ */
12
+ canRetry?: boolean;
13
+
14
+ /**
15
+ * If connection fails, node's errorCount increases. When errorCount is greater than removeNodeErrorCount,
16
+ * remove a node in the PoolCluster. (Default: 5)
17
+ */
18
+ removeNodeErrorCount?: number;
19
+
20
+ /**
21
+ * If connection fails, specifies the number of milliseconds before another connection attempt will be made.
22
+ * If set to 0, then node will be removed instead and never re-used. (Default: 0)
23
+ */
24
+ restoreNodeTimeout?: number;
25
+
26
+ /**
27
+ * The default selector. (Default: RR)
28
+ * RR: Select one alternately. (Round-Robin)
29
+ * RANDOM: Select the node by random function.
30
+ * ORDER: Select the first node available unconditionally.
31
+ */
32
+ defaultSelector?: string;
33
+ }
34
+ }
35
+
36
+ declare class PoolCluster extends EventEmitter {
37
+
38
+ config: PoolCluster.PoolClusterOptions;
39
+
40
+ add(config: PoolCluster.PoolClusterOptions): void;
41
+ add(group: string, config: PoolCluster.PoolClusterOptions): void;
42
+
43
+ end(): void;
44
+
45
+ getConnection(callback: (err: NodeJS.ErrnoException | null, connection: PoolConnection) => void): void;
46
+ getConnection(group: string, callback: (err: NodeJS.ErrnoException | null, connection: PoolConnection) => void): void;
47
+ getConnection(group: string, selector: string, callback: (err: NodeJS.ErrnoException | null, connection: PoolConnection) => void): void;
48
+
49
+ of(pattern: string, selector?: string): PoolCluster;
50
+
51
+ on(event: string, listener: Function): this;
52
+ on(event: 'remove', listener: (nodeId: number) => void): this;
53
+ on(event: 'connection', listener: (connection: PoolConnection) => void): this;
54
+ }
55
+
56
+ export = PoolCluster;
@@ -0,0 +1,8 @@
1
+
2
+ import Connection = require('./Connection');
3
+
4
+ declare class PoolConnection extends Connection {
5
+ release(): void;
6
+ }
7
+
8
+ export = PoolConnection;
@@ -0,0 +1,16 @@
1
+
2
+ declare interface Field {
3
+ constructor: {
4
+ name: 'Field'
5
+ };
6
+ db: string;
7
+ table: string;
8
+ name: string;
9
+ type: string;
10
+ length: number;
11
+ string: Function;
12
+ buffer: Function;
13
+ geometry: Function;
14
+ }
15
+
16
+ export = Field;
@@ -0,0 +1,22 @@
1
+
2
+ declare interface FieldPacket {
3
+ constructor: {
4
+ name: 'FieldPacket'
5
+ };
6
+ catalog: string;
7
+ charsetNr: number;
8
+ db: string;
9
+ decimals: number;
10
+ default: any;
11
+ flags: number;
12
+ length: number;
13
+ name: string;
14
+ orgName: string;
15
+ orgTable: string;
16
+ protocol41: boolean;
17
+ table: string;
18
+ type: number;
19
+ zerofill: boolean;
20
+ }
21
+
22
+ export = FieldPacket;
@@ -0,0 +1,16 @@
1
+
2
+ declare interface OkPacket {
3
+ constructor: {
4
+ name: 'OkPacket'
5
+ };
6
+ fieldCount: number;
7
+ affectedRows: number;
8
+ changedRows: number;
9
+ insertId: number;
10
+ serverStatus: number;
11
+ warningCount: number;
12
+ message: string;
13
+ procotol41: boolean;
14
+ }
15
+
16
+ export = OkPacket;
@@ -0,0 +1,14 @@
1
+
2
+ declare interface ResultSetHeader {
3
+ constructor: {
4
+ name: 'ResultSetHeader'
5
+ };
6
+ affectedRows: number;
7
+ fieldCount: number;
8
+ info: string;
9
+ insertId: number;
10
+ serverStatus: number;
11
+ warningStatus: number;
12
+ }
13
+
14
+ export = ResultSetHeader;
@@ -0,0 +1,10 @@
1
+
2
+ declare interface RowDataPacket {
3
+ constructor: {
4
+ name: 'RowDataPacket'
5
+ };
6
+ [column: string]: any;
7
+ [column: number]: any;
8
+ }
9
+
10
+ export = RowDataPacket;
@@ -0,0 +1,14 @@
1
+
2
+ import OkPacket = require('./OkPacket');
3
+ import RowDataPacket = require('./RowDataPacket');
4
+ import FieldPacket = require('./FieldPacket');
5
+ import Field = require('./Field');
6
+ import ResultSetHeader = require('./ResultSetHeader');
7
+
8
+ export {
9
+ OkPacket,
10
+ RowDataPacket,
11
+ FieldPacket,
12
+ Field,
13
+ ResultSetHeader
14
+ };
@@ -0,0 +1,132 @@
1
+
2
+ import Sequence = require('./Sequence');
3
+ import {OkPacket, RowDataPacket, FieldPacket} from '../packets/index';
4
+ import {Readable} from 'stream';
5
+
6
+ declare namespace Query {
7
+
8
+ export interface QueryOptions {
9
+ /**
10
+ * The SQL for the query
11
+ */
12
+ sql: string;
13
+
14
+ /**
15
+ * The values for the query
16
+ */
17
+ values?: any | any[] | { [param: string]: any };
18
+
19
+ /**
20
+ * Every operation takes an optional inactivity timeout option. This allows you to specify appropriate timeouts for
21
+ * operations. It is important to note that these timeouts are not part of the MySQL protocol, and rather timeout
22
+ * operations through the client. This means that when a timeout is reached, the connection it occurred on will be
23
+ * destroyed and no further operations can be performed.
24
+ */
25
+ timeout?: number;
26
+
27
+ /**
28
+ * Either a boolean or string. If true, tables will be nested objects. If string (e.g. '_'), tables will be
29
+ * nested as tableName_fieldName
30
+ */
31
+ nestTables?: any;
32
+
33
+ /**
34
+ * Determines if column values should be converted to native JavaScript types. It is not recommended (and may go away / change in the future)
35
+ * to disable type casting, but you can currently do so on either the connection or query level. (Default: true)
36
+ *
37
+ * You can also specify a function (field: any, next: () => void) => {} to do the type casting yourself.
38
+ *
39
+ * WARNING: YOU MUST INVOKE the parser using one of these three field functions in your custom typeCast callback. They can only be called once.
40
+ *
41
+ * field.string()
42
+ * field.buffer()
43
+ * field.geometry()
44
+ *
45
+ * are aliases for
46
+ *
47
+ * parser.parseLengthCodedString()
48
+ * parser.parseLengthCodedBuffer()
49
+ * parser.parseGeometryValue()
50
+ *
51
+ * You can find which field function you need to use by looking at: RowDataPacket.prototype._typeCast
52
+ */
53
+ typeCast?: any;
54
+ }
55
+
56
+ export interface StreamOptions {
57
+ /**
58
+ * Sets the max buffer size in objects of a stream
59
+ */
60
+ highWaterMark?: number;
61
+
62
+ /**
63
+ * The object mode of the stream (Default: true)
64
+ */
65
+ objectMode?: any;
66
+ }
67
+
68
+ export interface QueryError extends NodeJS.ErrnoException {
69
+ /**
70
+ * Either a MySQL server error (e.g. 'ER_ACCESS_DENIED_ERROR'),
71
+ * a node.js error (e.g. 'ECONNREFUSED') or an internal error
72
+ * (e.g. 'PROTOCOL_CONNECTION_LOST').
73
+ */
74
+ code: string;
75
+
76
+ /**
77
+ * The sql state marker
78
+ */
79
+ sqlStateMarker?: string;
80
+
81
+ /**
82
+ * The sql state
83
+ */
84
+ sqlState?: string;
85
+
86
+ /**
87
+ * The field count
88
+ */
89
+ fieldCount?: number;
90
+
91
+ /**
92
+ * Boolean, indicating if this error is terminal to the connection object.
93
+ */
94
+ fatal: boolean;
95
+ }
96
+ }
97
+
98
+ declare class Query extends Sequence {
99
+
100
+ /**
101
+ * The SQL for a constructed query
102
+ */
103
+ sql: string;
104
+
105
+ /**
106
+ * Emits a query packet to start the query
107
+ */
108
+ start(): void;
109
+
110
+ /**
111
+ * Determines the packet class to use given the first byte of the packet.
112
+ *
113
+ * @param firstByte The first byte of the packet
114
+ * @param parser The packet parser
115
+ */
116
+ determinePacket(firstByte: number, parser: any): any;
117
+
118
+ /**
119
+ * Creates a Readable stream with the given options
120
+ *
121
+ * @param options The options for the stream.
122
+ */
123
+ stream(options: Query.StreamOptions): Readable;
124
+
125
+ on(event: string, listener: Function): this;
126
+ on(event: 'error', listener: (err: Query.QueryError) => any): this;
127
+ on(event: 'fields', listener: (fields: FieldPacket, index: number) => any): this;
128
+ on(event: 'result', listener: (result: RowDataPacket | OkPacket, index: number) => any): this;
129
+ on(event: 'end', listener: () => any): this;
130
+ }
131
+
132
+ export = Query;
@@ -0,0 +1,5 @@
1
+
2
+ import {EventEmitter} from 'events';
3
+
4
+ declare class Sequence extends EventEmitter { }
5
+ export = Sequence;