|
| 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