Skip to content

Commit 764b4ba

Browse files
authored
Merge pull request #1211 from larshp/master
typings workaround, avoid git
2 parents 19149dc + 9c20c3e commit 764b4ba

18 files changed

+652
-9
lines changed

index.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {
44
PoolConnection as PromisePoolConnection
55
} from './promise';
66

7-
import * as mysql from 'mysql';
8-
export * from 'mysql';
7+
import * as mysql from './typings/mysql';
8+
export * from './typings/mysql';
99

1010
export interface Connection extends mysql.Connection {
1111
execute<
@@ -142,11 +142,11 @@ export interface Pool extends mysql.Connection {
142142
on(event: 'enqueue', listener: () => any): this;
143143
promise(promiseImpl?: PromiseConstructor): PromisePool;
144144
}
145-
145+
146146
type authPlugins =
147147
(pluginMetadata: { connection: Connection; command: string }) =>
148148
(pluginData: Buffer) => Promise<string>;
149-
149+
150150
export interface ConnectionOptions extends mysql.ConnectionOptions {
151151
charsetNumber?: number;
152152
compress?: boolean;

package-lock.json

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
],
3737
"files": [
3838
"lib",
39+
"typings",
3940
"index.js",
4041
"index.d.ts",
4142
"promise.js",
@@ -51,7 +52,6 @@
5152
"author": "Andrey Sidorov <[email protected]>",
5253
"license": "MIT",
5354
"dependencies": {
54-
"@types/mysql": "types/mysql",
5555
"denque": "^1.4.1",
5656
"generate-function": "^2.3.1",
5757
"iconv-lite": "^0.6.2",

typings/mysql/LICENSE.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

typings/mysql/index.d.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {}

typings/mysql/info.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
temporary workaround, see https://github.com/sidorares/node-mysql2/issues/1210

typings/mysql/lib/Connection.d.ts

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 commit comments

Comments
 (0)