mysql2 3.3.5 → 3.4.1

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.
Files changed (33) hide show
  1. package/index.d.ts +1 -205
  2. package/lib/packets/resultset_header.js +7 -0
  3. package/package.json +4 -9
  4. package/promise.d.ts +67 -91
  5. package/promise.js +19 -0
  6. package/typings/mysql/index.d.ts +81 -65
  7. package/typings/mysql/lib/Auth.d.ts +30 -0
  8. package/typings/mysql/lib/Connection.d.ts +355 -274
  9. package/typings/mysql/lib/Pool.d.ts +75 -74
  10. package/typings/mysql/lib/PoolCluster.d.ts +75 -45
  11. package/typings/mysql/lib/PoolConnection.d.ts +6 -5
  12. package/typings/mysql/lib/Server.d.ts +4 -6
  13. package/typings/mysql/lib/constants/CharsetToEncoding.d.ts +8 -0
  14. package/typings/mysql/lib/constants/Charsets.d.ts +326 -0
  15. package/typings/mysql/lib/constants/Types.d.ts +68 -0
  16. package/typings/mysql/lib/constants/index.d.ts +5 -0
  17. package/typings/mysql/lib/parsers/ParserCache.d.ts +4 -0
  18. package/typings/mysql/lib/parsers/index.d.ts +3 -0
  19. package/typings/mysql/lib/protocol/packets/Field.d.ts +12 -13
  20. package/typings/mysql/lib/protocol/packets/FieldPacket.d.ts +18 -19
  21. package/typings/mysql/lib/protocol/packets/OkPacket.d.ts +12 -13
  22. package/typings/mysql/lib/protocol/packets/ResultSetHeader.d.ts +11 -12
  23. package/typings/mysql/lib/protocol/packets/RowDataPacket.d.ts +6 -7
  24. package/typings/mysql/lib/protocol/packets/index.d.ts +14 -15
  25. package/typings/mysql/lib/protocol/packets/params/ErrorPacketParams.d.ts +1 -1
  26. package/typings/mysql/lib/protocol/packets/params/OkPacketParams.d.ts +1 -1
  27. package/typings/mysql/lib/protocol/sequences/ExecutableBase.ts +104 -0
  28. package/typings/mysql/lib/protocol/sequences/Prepare.d.ts +55 -42
  29. package/typings/mysql/lib/protocol/sequences/Query.d.ts +145 -142
  30. package/typings/mysql/lib/protocol/sequences/QueryableBase.ts +104 -0
  31. package/typings/mysql/lib/protocol/sequences/Sequence.d.ts +3 -3
  32. package/typings/mysql/lib/protocol/sequences/promise/ExecutableBase.ts +69 -0
  33. package/typings/mysql/lib/protocol/sequences/promise/QueryableBase.ts +69 -0
@@ -1,148 +1,151 @@
1
+ import { Sequence } from './Sequence.js';
2
+ import { OkPacket, RowDataPacket, FieldPacket } from '../packets/index.js';
3
+ import { Readable } from 'stream';
4
+
5
+ export interface QueryOptions {
6
+ /**
7
+ * The SQL for the query
8
+ */
9
+ sql: string;
10
+
11
+ /**
12
+ * The values for the query
13
+ */
14
+ values?: any | any[] | { [param: string]: any };
15
+
16
+ /**
17
+ * This overrides the namedPlaceholders option set at the connection level.
18
+ */
19
+ namedPlaceholders?: boolean;
20
+
21
+ /**
22
+ * Every operation takes an optional inactivity timeout option. This allows you to specify appropriate timeouts for
23
+ * operations. It is important to note that these timeouts are not part of the MySQL protocol, and rather timeout
24
+ * operations through the client. This means that when a timeout is reached, the connection it occurred on will be
25
+ * destroyed and no further operations can be performed.
26
+ */
27
+ timeout?: number;
28
+
29
+ /**
30
+ * Either a boolean or string. If true, tables will be nested objects. If string (e.g. '_'), tables will be
31
+ * nested as tableName_fieldName
32
+ */
33
+ nestTables?: any;
34
+
35
+ /**
36
+ * Determines if column values should be converted to native JavaScript types. It is not recommended (and may go away / change in the future)
37
+ * to disable type casting, but you can currently do so on either the connection or query level. (Default: true)
38
+ *
39
+ * You can also specify a function (field: any, next: () => void) => {} to do the type casting yourself.
40
+ *
41
+ * WARNING: YOU MUST INVOKE the parser using one of these three field functions in your custom typeCast callback. They can only be called once.
42
+ *
43
+ * field.string()
44
+ * field.buffer()
45
+ * field.geometry()
46
+ *
47
+ * are aliases for
48
+ *
49
+ * parser.parseLengthCodedString()
50
+ * parser.parseLengthCodedBuffer()
51
+ * parser.parseGeometryValue()
52
+ *
53
+ * You can find which field function you need to use by looking at: RowDataPacket.prototype._typeCast
54
+ */
55
+ typeCast?: any;
56
+
57
+ /**
58
+ * This overrides the same option set at the connection level.
59
+ *
60
+ */
61
+ rowsAsArray?: boolean;
62
+
63
+ /**
64
+ * By specifying a function that returns a readable stream, an arbitrary stream can be sent when sending a local fs file.
65
+ */
66
+ infileStreamFactory?: (path: string) => Readable;
67
+ }
68
+
69
+ export interface StreamOptions {
70
+ /**
71
+ * Sets the max buffer size in objects of a stream
72
+ */
73
+ highWaterMark?: number;
1
74
 
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
- * This overrides the namedPlaceholders option set at the connection level.
21
- */
22
- namedPlaceholders?: boolean;
23
-
24
- /**
25
- * Every operation takes an optional inactivity timeout option. This allows you to specify appropriate timeouts for
26
- * operations. It is important to note that these timeouts are not part of the MySQL protocol, and rather timeout
27
- * operations through the client. This means that when a timeout is reached, the connection it occurred on will be
28
- * destroyed and no further operations can be performed.
29
- */
30
- timeout?: number;
31
-
32
- /**
33
- * Either a boolean or string. If true, tables will be nested objects. If string (e.g. '_'), tables will be
34
- * nested as tableName_fieldName
35
- */
36
- nestTables?: any;
37
-
38
- /**
39
- * Determines if column values should be converted to native JavaScript types. It is not recommended (and may go away / change in the future)
40
- * to disable type casting, but you can currently do so on either the connection or query level. (Default: true)
41
- *
42
- * You can also specify a function (field: any, next: () => void) => {} to do the type casting yourself.
43
- *
44
- * WARNING: YOU MUST INVOKE the parser using one of these three field functions in your custom typeCast callback. They can only be called once.
45
- *
46
- * field.string()
47
- * field.buffer()
48
- * field.geometry()
49
- *
50
- * are aliases for
51
- *
52
- * parser.parseLengthCodedString()
53
- * parser.parseLengthCodedBuffer()
54
- * parser.parseGeometryValue()
55
- *
56
- * You can find which field function you need to use by looking at: RowDataPacket.prototype._typeCast
57
- */
58
- typeCast?: any;
59
-
60
- /**
61
- * This overrides the same option set at the connection level.
62
- *
63
- */
64
- rowsAsArray?: boolean
65
-
66
- /**
67
- * By specifying a function that returns a readable stream, an arbitrary stream can be sent when sending a local fs file.
68
- */
69
- infileStreamFactory?: (path: string) => Readable;
70
- }
71
-
72
- export interface StreamOptions {
73
- /**
74
- * Sets the max buffer size in objects of a stream
75
- */
76
- highWaterMark?: number;
77
-
78
- /**
79
- * The object mode of the stream (Default: true)
80
- */
81
- objectMode?: any;
82
- }
83
-
84
- export interface QueryError extends NodeJS.ErrnoException {
85
- /**
86
- * Either a MySQL server error (e.g. 'ER_ACCESS_DENIED_ERROR'),
87
- * a node.js error (e.g. 'ECONNREFUSED') or an internal error
88
- * (e.g. 'PROTOCOL_CONNECTION_LOST').
89
- */
90
- code: string;
91
-
92
- /**
93
- * The sql state marker
94
- */
95
- sqlStateMarker?: string;
96
-
97
- /**
98
- * The sql state
99
- */
100
- sqlState?: string;
101
-
102
- /**
103
- * The field count
104
- */
105
- fieldCount?: number;
106
-
107
- /**
108
- * Boolean, indicating if this error is terminal to the connection object.
109
- */
110
- fatal: boolean;
111
- }
75
+ /**
76
+ * The object mode of the stream (Default: true)
77
+ */
78
+ objectMode?: any;
112
79
  }
113
80
 
114
- declare class Query extends Sequence {
81
+ export interface QueryError extends NodeJS.ErrnoException {
82
+ /**
83
+ * Either a MySQL server error (e.g. 'ER_ACCESS_DENIED_ERROR'),
84
+ * a node.js error (e.g. 'ECONNREFUSED') or an internal error
85
+ * (e.g. 'PROTOCOL_CONNECTION_LOST').
86
+ */
87
+ code: string;
88
+
89
+ /**
90
+ * The sql state marker
91
+ */
92
+ sqlStateMarker?: string;
93
+
94
+ /**
95
+ * The sql state
96
+ */
97
+ sqlState?: string;
98
+
99
+ /**
100
+ * The field count
101
+ */
102
+ fieldCount?: number;
103
+
104
+ /**
105
+ * Boolean, indicating if this error is terminal to the connection object.
106
+ */
107
+ fatal: boolean;
108
+ }
115
109
 
116
- /**
117
- * The SQL for a constructed query
118
- */
119
- sql: string;
120
-
121
- /**
122
- * Emits a query packet to start the query
123
- */
124
- start(): void;
125
-
126
- /**
127
- * Determines the packet class to use given the first byte of the packet.
128
- *
129
- * @param firstByte The first byte of the packet
130
- * @param parser The packet parser
131
- */
132
- determinePacket(firstByte: number, parser: any): any;
133
-
134
- /**
135
- * Creates a Readable stream with the given options
136
- *
137
- * @param options The options for the stream.
138
- */
139
- stream(options?: Query.StreamOptions): Readable;
140
-
141
- on(event: string, listener: Function): this;
142
- on(event: 'error', listener: (err: Query.QueryError) => any): this;
143
- on(event: 'fields', listener: (fields: FieldPacket, index: number) => any): this;
144
- on(event: 'result', listener: (result: RowDataPacket | OkPacket, index: number) => any): this;
145
- on(event: 'end', listener: () => any): this;
110
+ declare class Query extends Sequence {
111
+ /**
112
+ * The SQL for a constructed query
113
+ */
114
+ sql: string;
115
+
116
+ /**
117
+ * Emits a query packet to start the query
118
+ */
119
+ start(): void;
120
+
121
+ /**
122
+ * Determines the packet class to use given the first byte of the packet.
123
+ *
124
+ * @param firstByte The first byte of the packet
125
+ * @param parser The packet parser
126
+ */
127
+ determinePacket(firstByte: number, parser: any): any;
128
+
129
+ /**
130
+ * Creates a Readable stream with the given options
131
+ *
132
+ * @param options The options for the stream.
133
+ */
134
+ stream(options?: StreamOptions): Readable;
135
+
136
+ on(event: string, listener: (args: any[]) => void): this;
137
+ on(event: 'error', listener: (err: QueryError) => any): this;
138
+ on(
139
+ event: 'fields',
140
+ listener: (fields: FieldPacket, index: number) => any
141
+ ): this;
142
+ on(
143
+ event: 'result',
144
+ listener: (result: RowDataPacket | OkPacket, index: number) => any
145
+ ): this;
146
+ on(event: 'end', listener: () => any): this;
146
147
  }
147
148
 
148
- export = Query;
149
+ export type QueryableConstructor<T = object> = new (...args: any[]) => T;
150
+
151
+ export { Query };
@@ -0,0 +1,104 @@
1
+ import {
2
+ OkPacket,
3
+ FieldPacket,
4
+ RowDataPacket,
5
+ ResultSetHeader,
6
+ } from '../packets/index.js';
7
+ import {
8
+ Query,
9
+ QueryError,
10
+ QueryOptions,
11
+ QueryableConstructor,
12
+ } from './Query.js';
13
+
14
+ export function QueryableBase<T extends QueryableConstructor>(
15
+ Base: T = {} as T
16
+ ) {
17
+ return class extends Base {
18
+ query<
19
+ T extends
20
+ | RowDataPacket[][]
21
+ | RowDataPacket[]
22
+ | OkPacket
23
+ | OkPacket[]
24
+ | ResultSetHeader
25
+ >(
26
+ sql: string,
27
+ callback?: (
28
+ err: QueryError | null,
29
+ result: T,
30
+ fields: FieldPacket[]
31
+ ) => any
32
+ ): Query;
33
+ query<
34
+ T extends
35
+ | RowDataPacket[][]
36
+ | RowDataPacket[]
37
+ | OkPacket
38
+ | OkPacket[]
39
+ | ResultSetHeader
40
+ >(
41
+ sql: string,
42
+ values: any | any[] | { [param: string]: any },
43
+ callback?: (
44
+ err: QueryError | null,
45
+ result: T,
46
+ fields: FieldPacket[]
47
+ ) => any
48
+ ): Query;
49
+ query<
50
+ T extends
51
+ | RowDataPacket[][]
52
+ | RowDataPacket[]
53
+ | OkPacket
54
+ | OkPacket[]
55
+ | ResultSetHeader
56
+ >(
57
+ options: QueryOptions,
58
+ callback?: (
59
+ err: QueryError | null,
60
+ result: T,
61
+ fields?: FieldPacket[]
62
+ ) => any
63
+ ): Query;
64
+ query<
65
+ T extends
66
+ | RowDataPacket[][]
67
+ | RowDataPacket[]
68
+ | OkPacket
69
+ | OkPacket[]
70
+ | ResultSetHeader
71
+ >(
72
+ options: QueryOptions,
73
+ values: any | any[] | { [param: string]: any },
74
+ callback?: (
75
+ err: QueryError | null,
76
+ result: T,
77
+ fields: FieldPacket[]
78
+ ) => any
79
+ ): Query;
80
+
81
+ // Implementing all overload variations
82
+ /* eslint-disable @typescript-eslint/no-unused-vars */
83
+ query(
84
+ options: QueryOptions | string,
85
+ values?:
86
+ | any
87
+ | any[]
88
+ | { [param: string]: any }
89
+ | ((
90
+ err: QueryError | null,
91
+ result: any,
92
+ fields?: FieldPacket[]
93
+ ) => any),
94
+ callback?: (
95
+ err: QueryError | null,
96
+ result: any,
97
+ fields: FieldPacket[]
98
+ ) => any
99
+ ): Query {
100
+ return new Query();
101
+ }
102
+ /* eslint-enable @typescript-eslint/no-unused-vars */
103
+ };
104
+ }
@@ -1,5 +1,5 @@
1
+ import { EventEmitter } from 'events';
1
2
 
2
- import {EventEmitter} from 'events';
3
+ declare class Sequence extends EventEmitter {}
3
4
 
4
- declare class Sequence extends EventEmitter { }
5
- export = Sequence;
5
+ export { Sequence };
@@ -0,0 +1,69 @@
1
+ import {
2
+ OkPacket,
3
+ FieldPacket,
4
+ RowDataPacket,
5
+ ResultSetHeader,
6
+ } from '../../packets/index.js';
7
+ import { Query, QueryOptions, QueryableConstructor } from '../Query.js';
8
+
9
+ export function ExecutableBase<T extends QueryableConstructor>(
10
+ Base: T = {} as T
11
+ ) {
12
+ return class extends Base {
13
+ execute<
14
+ T extends
15
+ | RowDataPacket[][]
16
+ | RowDataPacket[]
17
+ | OkPacket
18
+ | OkPacket[]
19
+ | ResultSetHeader
20
+ >(sql: string): Promise<[T, FieldPacket[]]>;
21
+ execute<
22
+ T extends
23
+ | RowDataPacket[][]
24
+ | RowDataPacket[]
25
+ | OkPacket
26
+ | OkPacket[]
27
+ | ResultSetHeader
28
+ >(
29
+ sql: string,
30
+ values: any | any[] | { [param: string]: any }
31
+ ): Promise<[T, FieldPacket[]]>;
32
+ execute<
33
+ T extends
34
+ | RowDataPacket[][]
35
+ | RowDataPacket[]
36
+ | OkPacket
37
+ | OkPacket[]
38
+ | ResultSetHeader
39
+ >(options: QueryOptions): Promise<[T, FieldPacket[]]>;
40
+ execute<
41
+ T extends
42
+ | RowDataPacket[][]
43
+ | RowDataPacket[]
44
+ | OkPacket
45
+ | OkPacket[]
46
+ | ResultSetHeader
47
+ >(
48
+ options: QueryOptions,
49
+ values: any | any[] | { [param: string]: any }
50
+ ): Promise<[T, FieldPacket[]]>;
51
+
52
+ // Implementing all overload variations
53
+ /* eslint-disable @typescript-eslint/no-unused-vars */
54
+ execute<
55
+ T extends
56
+ | RowDataPacket[][]
57
+ | RowDataPacket[]
58
+ | OkPacket
59
+ | OkPacket[]
60
+ | ResultSetHeader
61
+ >(
62
+ sql: string | QueryOptions,
63
+ values?: any | any[] | { [param: string]: any }
64
+ ): Promise<[T, FieldPacket[]]> {
65
+ return new Promise(() => new Query());
66
+ }
67
+ /* eslint-enable @typescript-eslint/no-unused-vars */
68
+ };
69
+ }
@@ -0,0 +1,69 @@
1
+ import {
2
+ OkPacket,
3
+ FieldPacket,
4
+ RowDataPacket,
5
+ ResultSetHeader,
6
+ } from '../../packets/index.js';
7
+ import { Query, QueryOptions, QueryableConstructor } from '../Query.js';
8
+
9
+ export function QueryableBase<T extends QueryableConstructor>(
10
+ Base: T = {} as T
11
+ ) {
12
+ return class extends Base {
13
+ query<
14
+ T extends
15
+ | RowDataPacket[][]
16
+ | RowDataPacket[]
17
+ | OkPacket
18
+ | OkPacket[]
19
+ | ResultSetHeader
20
+ >(sql: string): Promise<[T, FieldPacket[]]>;
21
+ query<
22
+ T extends
23
+ | RowDataPacket[][]
24
+ | RowDataPacket[]
25
+ | OkPacket
26
+ | OkPacket[]
27
+ | ResultSetHeader
28
+ >(
29
+ sql: string,
30
+ values: any | any[] | { [param: string]: any }
31
+ ): Promise<[T, FieldPacket[]]>;
32
+ query<
33
+ T extends
34
+ | RowDataPacket[][]
35
+ | RowDataPacket[]
36
+ | OkPacket
37
+ | OkPacket[]
38
+ | ResultSetHeader
39
+ >(options: QueryOptions): Promise<[T, FieldPacket[]]>;
40
+ query<
41
+ T extends
42
+ | RowDataPacket[][]
43
+ | RowDataPacket[]
44
+ | OkPacket
45
+ | OkPacket[]
46
+ | ResultSetHeader
47
+ >(
48
+ options: QueryOptions,
49
+ values: any | any[] | { [param: string]: any }
50
+ ): Promise<[T, FieldPacket[]]>;
51
+
52
+ // Implementing all overload variations
53
+ /* eslint-disable @typescript-eslint/no-unused-vars */
54
+ query<
55
+ T extends
56
+ | RowDataPacket[][]
57
+ | RowDataPacket[]
58
+ | OkPacket
59
+ | OkPacket[]
60
+ | ResultSetHeader
61
+ >(
62
+ sql: string | QueryOptions,
63
+ values?: any | any[] | { [param: string]: any }
64
+ ): Promise<[T, FieldPacket[]]> {
65
+ return new Promise(() => new Query());
66
+ }
67
+ /* eslint-enable @typescript-eslint/no-unused-vars */
68
+ };
69
+ }