mysql2 2.2.2 → 2.3.0

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.
@@ -4,6 +4,7 @@ const process = require('process');
4
4
 
5
5
  const Pool = require('./pool.js');
6
6
  const PoolConfig = require('./pool_config.js');
7
+ const Connection = require('./connection.js');
7
8
  const EventEmitter = require('events').EventEmitter;
8
9
 
9
10
  /**
@@ -46,6 +47,62 @@ class PoolNamespace {
46
47
  });
47
48
  }
48
49
 
50
+ /**
51
+ * pool cluster query
52
+ * @param {*} sql
53
+ * @param {*} values
54
+ * @param {*} cb
55
+ * @returns query
56
+ */
57
+ query(sql, values, cb) {
58
+ const query = Connection.createQuery(sql, values, cb, {});
59
+ this.getConnection((err, conn) => {
60
+ if (err) {
61
+ if (typeof query.onResult === 'function') {
62
+ query.onResult(err);
63
+ } else {
64
+ query.emit('error', err);
65
+ }
66
+ return;
67
+ }
68
+ try {
69
+ conn.query(query).once('end', () => {
70
+ conn.release();
71
+ });
72
+ } catch (e) {
73
+ conn.release();
74
+ throw e;
75
+ }
76
+ });
77
+ return query;
78
+ }
79
+
80
+ /**
81
+ * pool cluster execute
82
+ * @param {*} sql
83
+ * @param {*} values
84
+ * @param {*} cb
85
+ */
86
+ execute(sql, values, cb) {
87
+ if (typeof values === 'function') {
88
+ cb = values;
89
+ values = [];
90
+ }
91
+ this.getConnection((err, conn) => {
92
+ if (err) {
93
+ return cb(err);
94
+ }
95
+ try {
96
+ conn.execute(sql, values, cb).once('end', () => {
97
+ conn.release();
98
+ });
99
+ } catch (e) {
100
+ conn.release();
101
+ throw e;
102
+ }
103
+ });
104
+ }
105
+
49
106
  _getClusterNode() {
50
107
  const foundNodeIds = this._cluster._findNodeIds(this._pattern);
51
108
  if (foundNodeIds.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mysql2",
3
- "version": "2.2.2",
3
+ "version": "2.3.0",
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",
@@ -43,7 +44,8 @@
43
44
  ],
44
45
  "exports": {
45
46
  ".": "./index.js",
46
- "./promise": "./promise.js"
47
+ "./promise": "./promise.js",
48
+ "./promise.js": "./promise.js"
47
49
  },
48
50
  "engines": {
49
51
  "node": ">= 8.0"
@@ -51,7 +53,6 @@
51
53
  "author": "Andrey Sidorov <sidorares@yandex.ru>",
52
54
  "license": "MIT",
53
55
  "dependencies": {
54
- "@types/mysql": "^2.15.7",
55
56
  "denque": "^1.4.1",
56
57
  "generate-function": "^2.3.1",
57
58
  "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 }
package/promise.js CHANGED
@@ -9,6 +9,7 @@ function makeDoneCb(resolve, reject, localErr) {
9
9
  localErr.message = err.message;
10
10
  localErr.code = err.code;
11
11
  localErr.errno = err.errno;
12
+ localErr.sql = err.sql;
12
13
  localErr.sqlState = err.sqlState;
13
14
  localErr.sqlMessage = err.sqlMessage;
14
15
  reject(localErr);
@@ -427,8 +428,120 @@ function createPool(opts) {
427
428
  'format'
428
429
  ]);
429
430
 
431
+ class PromisePoolCluster extends EventEmitter {
432
+ constructor(poolCluster, thePromise) {
433
+ super();
434
+ this.poolCluster = poolCluster;
435
+ this.Promise = thePromise || Promise;
436
+ inheritEvents(poolCluster, this, ['acquire', 'connection', 'enqueue', 'release']);
437
+ }
438
+
439
+ getConnection() {
440
+ const corePoolCluster = this.poolCluster;
441
+ return new this.Promise((resolve, reject) => {
442
+ corePoolCluster.getConnection((err, coreConnection) => {
443
+ if (err) {
444
+ reject(err);
445
+ } else {
446
+ resolve(new PromisePoolConnection(coreConnection, this.Promise));
447
+ }
448
+ });
449
+ });
450
+ }
451
+
452
+ query(sql, args) {
453
+ const corePoolCluster = this.poolCluster;
454
+ const localErr = new Error();
455
+ if (typeof args === 'function') {
456
+ throw new Error(
457
+ 'Callback function is not available with promise clients.'
458
+ );
459
+ }
460
+ return new this.Promise((resolve, reject) => {
461
+ const done = makeDoneCb(resolve, reject, localErr);
462
+ corePoolCluster.query(sql, args, done);
463
+ });
464
+ }
465
+
466
+ execute(sql, args) {
467
+ const corePoolCluster = this.poolCluster;
468
+ const localErr = new Error();
469
+ if (typeof args === 'function') {
470
+ throw new Error(
471
+ 'Callback function is not available with promise clients.'
472
+ );
473
+ }
474
+ return new this.Promise((resolve, reject) => {
475
+ const done = makeDoneCb(resolve, reject, localErr);
476
+ corePoolCluster.execute(sql, args, done);
477
+ });
478
+ }
479
+
480
+ of(pattern, selector) {
481
+ return new PromisePoolCluster(
482
+ this.poolCluster.of(pattern, selector),
483
+ this.Promise
484
+ );
485
+ }
486
+
487
+ end() {
488
+ const corePoolCluster = this.poolCluster;
489
+ const localErr = new Error();
490
+ return new this.Promise((resolve, reject) => {
491
+ corePoolCluster.end(err => {
492
+ if (err) {
493
+ localErr.message = err.message;
494
+ localErr.code = err.code;
495
+ localErr.errno = err.errno;
496
+ localErr.sqlState = err.sqlState;
497
+ localErr.sqlMessage = err.sqlMessage;
498
+ reject(localErr);
499
+ } else {
500
+ resolve();
501
+ }
502
+ });
503
+ });
504
+ }
505
+ }
506
+
507
+ /**
508
+ * proxy poolCluster synchronous functions
509
+ */
510
+ (function (functionsToWrap) {
511
+ for (let i = 0; functionsToWrap && i < functionsToWrap.length; i++) {
512
+ const func = functionsToWrap[i];
513
+
514
+ if (
515
+ typeof core.PoolCluster.prototype[func] === 'function' &&
516
+ PromisePoolCluster.prototype[func] === undefined
517
+ ) {
518
+ PromisePoolCluster.prototype[func] = (function factory(funcName) {
519
+ return function () {
520
+ return core.PoolCluster.prototype[funcName].apply(this.poolCluster, arguments);
521
+ };
522
+ })(func);
523
+ }
524
+ }
525
+ })([
526
+ 'add'
527
+ ]);
528
+
529
+ function createPoolCluster(opts) {
530
+ const corePoolCluster = core.createPoolCluster(opts);
531
+ const thePromise = (opts && opts.Promise) || Promise;
532
+ if (!thePromise) {
533
+ throw new Error(
534
+ 'no Promise implementation available.' +
535
+ 'Use promise-enabled node version or pass userland Promise' +
536
+ " implementation as parameter, for example: { Promise: require('bluebird') }"
537
+ );
538
+ }
539
+ return new PromisePoolCluster(corePoolCluster, thePromise);
540
+ }
541
+
430
542
  exports.createConnection = createConnection;
431
543
  exports.createPool = createPool;
544
+ exports.createPoolCluster = createPoolCluster;
432
545
  exports.escape = core.escape;
433
546
  exports.escapeId = core.escapeId;
434
547
  exports.format = core.format;
@@ -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,246 @@
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
+ /**
153
+ * Return each row as an array, not as an object.
154
+ * This is useful when you have duplicate column names.
155
+ * This can also be set in the `QueryOption` object to be applied per-query.
156
+ */
157
+ rowsAsArray?: boolean
158
+ }
159
+
160
+ export interface SslOptions {
161
+ /**
162
+ * A string or buffer holding the PFX or PKCS12 encoded private key, certificate and CA certificates
163
+ */
164
+ pfx?: string;
165
+
166
+ /**
167
+ * A string holding the PEM encoded private key
168
+ */
169
+ key?: string;
170
+
171
+ /**
172
+ * A string of passphrase for the private key or pfx
173
+ */
174
+ passphrase?: string;
175
+
176
+ /**
177
+ * A string holding the PEM encoded certificate
178
+ */
179
+ cert?: string;
180
+
181
+ /**
182
+ * Either a string or list of strings of PEM encoded CA certificates to trust.
183
+ */
184
+ ca?: string | string[];
185
+
186
+ /**
187
+ * Either a string or list of strings of PEM encoded CRLs (Certificate Revocation List)
188
+ */
189
+ crl?: string | string[];
190
+
191
+ /**
192
+ * A string describing the ciphers to use or exclude
193
+ */
194
+ ciphers?: string;
195
+
196
+ /**
197
+ * You can also connect to a MySQL server without properly providing the appropriate CA to trust. You should not do this.
198
+ */
199
+ rejectUnauthorized?: boolean;
200
+ }
201
+ }
202
+
203
+ declare class Connection extends EventEmitter {
204
+
205
+ config: Connection.ConnectionOptions;
206
+ threadId: number;
207
+ authorized: boolean;
208
+
209
+ static createQuery<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(sql: string, callback?: (err: Query.QueryError | null, result: T, fields: FieldPacket[]) => any): Query;
210
+ 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;
211
+
212
+ beginTransaction(callback: (err: Query.QueryError | null) => void): void;
213
+
214
+ connect(callback?: (err: Query.QueryError | null) => void): void;
215
+
216
+ commit(callback?: (err: Query.QueryError | null) => void): void;
217
+
218
+ changeUser(options: Connection.ConnectionOptions, callback?: (err: Query.QueryError | null) => void): void;
219
+
220
+ query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(sql: string, callback?: (err: Query.QueryError | null, result: T, fields: FieldPacket[]) => any): Query;
221
+ 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;
222
+ query<T extends RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader>(options: Query.QueryOptions, callback?: (err: Query.QueryError | null, result: T, fields?: FieldPacket[]) => any): Query;
223
+ 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;
224
+
225
+ end(callback?: (err: Query.QueryError | null) => void): void;
226
+ end(options: any, callback?: (err: Query.QueryError | null) => void): void;
227
+
228
+ destroy(): void;
229
+
230
+ pause(): void;
231
+
232
+ resume(): void;
233
+
234
+ escape(value: any): string;
235
+
236
+ escapeId(value: string): string;
237
+ escapeId(values: string[]): string;
238
+
239
+ format(sql: string, values?: any | any[] | { [param: string]: any }): string;
240
+
241
+ on(event: string, listener: Function): this;
242
+
243
+ rollback(callback: () => void): void;
244
+ }
245
+
246
+ export = Connection;