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.
@@ -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,138 @@
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
+ * This overrides the same option set at the connection level.
57
+ *
58
+ */
59
+ rowsAsArray?: boolean
60
+ }
61
+
62
+ export interface StreamOptions {
63
+ /**
64
+ * Sets the max buffer size in objects of a stream
65
+ */
66
+ highWaterMark?: number;
67
+
68
+ /**
69
+ * The object mode of the stream (Default: true)
70
+ */
71
+ objectMode?: any;
72
+ }
73
+
74
+ export interface QueryError extends NodeJS.ErrnoException {
75
+ /**
76
+ * Either a MySQL server error (e.g. 'ER_ACCESS_DENIED_ERROR'),
77
+ * a node.js error (e.g. 'ECONNREFUSED') or an internal error
78
+ * (e.g. 'PROTOCOL_CONNECTION_LOST').
79
+ */
80
+ code: string;
81
+
82
+ /**
83
+ * The sql state marker
84
+ */
85
+ sqlStateMarker?: string;
86
+
87
+ /**
88
+ * The sql state
89
+ */
90
+ sqlState?: string;
91
+
92
+ /**
93
+ * The field count
94
+ */
95
+ fieldCount?: number;
96
+
97
+ /**
98
+ * Boolean, indicating if this error is terminal to the connection object.
99
+ */
100
+ fatal: boolean;
101
+ }
102
+ }
103
+
104
+ declare class Query extends Sequence {
105
+
106
+ /**
107
+ * The SQL for a constructed query
108
+ */
109
+ sql: string;
110
+
111
+ /**
112
+ * Emits a query packet to start the query
113
+ */
114
+ start(): void;
115
+
116
+ /**
117
+ * Determines the packet class to use given the first byte of the packet.
118
+ *
119
+ * @param firstByte The first byte of the packet
120
+ * @param parser The packet parser
121
+ */
122
+ determinePacket(firstByte: number, parser: any): any;
123
+
124
+ /**
125
+ * Creates a Readable stream with the given options
126
+ *
127
+ * @param options The options for the stream.
128
+ */
129
+ stream(options: Query.StreamOptions): Readable;
130
+
131
+ on(event: string, listener: Function): this;
132
+ on(event: 'error', listener: (err: Query.QueryError) => any): this;
133
+ on(event: 'fields', listener: (fields: FieldPacket, index: number) => any): this;
134
+ on(event: 'result', listener: (result: RowDataPacket | OkPacket, index: number) => any): this;
135
+ on(event: 'end', listener: () => any): this;
136
+ }
137
+
138
+ export = Query;
@@ -0,0 +1,5 @@
1
+
2
+ import {EventEmitter} from 'events';
3
+
4
+ declare class Sequence extends EventEmitter { }
5
+ export = Sequence;