Skip to content

Commit d590c37

Browse files
committed
added types and tests
1 parent 5cc6fe3 commit d590c37

File tree

12 files changed

+146
-9
lines changed

12 files changed

+146
-9
lines changed

.eslintrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
"es6": true
1010
},
1111
"rules": {
12+
"@typescript-eslint/typedef": [
13+
"error",
14+
{
15+
"arrowParameter": true,
16+
"variableDeclaration": true
17+
}
18+
],
1219
"template-curly-spacing": ["error", "never"],
1320
"prefer-template": "error",
1421
"no-useless-call": "error",

index.d.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
Connection as PromiseConnection,
33
Pool as PromisePool,
4-
PoolConnection as PromisePoolConnection
4+
PoolConnection as PromisePoolConnection,
55
} from './promise';
66

77
import * as mysql from './typings/mysql';
@@ -74,9 +74,16 @@ export interface Connection extends mysql.Connection {
7474
promise(promiseImpl?: PromiseConstructor): PromiseConnection;
7575
unprepare(sql: string): mysql.PrepareStatementInfo;
7676
prepare(sql: string, callback?: (err: mysql.QueryError | null, statement: mysql.PrepareStatementInfo) => any): mysql.Prepare;
77+
serverHandshake(args: any): any;
78+
writeOk(args?: mysql.OkPacketParams): void;
79+
writeError(args?: mysql.ErrorPacketParams): void;
80+
writeEof(warnings?: number, statusFlags?: number): void;
81+
writeTextResult(rows?: Array<any>, columns?: Array<any>): void;
82+
writePacket(packet: any): void;
83+
sequenceId: number;
7784
}
7885

79-
export interface PoolConnection extends mysql.PoolConnection, Connection {
86+
export interface PoolConnection extends Connection {
8087
promise(promiseImpl?: PromiseConstructor): PromisePoolConnection;
8188
}
8289

@@ -153,6 +160,8 @@ export interface Pool extends mysql.Connection {
153160
promise(promiseImpl?: PromiseConstructor): PromisePool;
154161
unprepare(sql: string): mysql.PrepareStatementInfo;
155162
prepare(sql: string, callback?: (err: mysql.QueryError | null, statement: mysql.PrepareStatementInfo) => any): mysql.Prepare;
163+
164+
config: mysql.PoolOptions;
156165
}
157166

158167
type authPlugins = (pluginMetadata: {

promise.d.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
FieldPacket,
66
QueryOptions,
77
ConnectionOptions,
8-
PoolOptions
8+
PoolOptions,
9+
Pool as CorePool
910
} from './index';
1011

1112
import { EventEmitter } from 'events';
@@ -131,6 +132,13 @@ export interface Pool extends EventEmitter {
131132
on(event: 'release', listener: (connection: PoolConnection) => any): this;
132133
on(event: 'enqueue', listener: () => any): this;
133134
end(): Promise<void>;
135+
136+
escape(value: any): string;
137+
escapeId(value: string): string;
138+
escapeId(values: string[]): string;
139+
format(sql: string, values?: any | any[] | { [param: string]: any }): string;
140+
141+
pool: CorePool;
134142
}
135143

136144
export function createConnection(connectionUri: string): Promise<Connection>;
@@ -143,3 +151,7 @@ export interface PreparedStatementInfo {
143151
close(): Promise<void>;
144152
execute(parameters: any[]): Promise<[RowDataPacket[][] | RowDataPacket[] | OkPacket | OkPacket[] | ResultSetHeader, FieldPacket[]]>;
145153
}
154+
155+
export interface PromisePoolConnection extends Connection {
156+
destroy(): any;
157+
}

tests.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"listEmittedFiles": false
77
},
88
"files": [
9-
"typings/test/server.ts"
9+
"typings/test/server.ts",
10+
"typings/test/connection.ts",
11+
"typings/test/pool.ts"
1012
],
1113
"typeRoots": [
1214
"./typings",

typings/mysql/index.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export function format(sql: string, values: any, stringifyObjects?: boolean, tim
2424
export function raw(sql: string): {
2525
toSqlString: () => string
2626
};
27+
export function createServer(handler: (conn: BaseConnection) => any): Server;
2728

2829
export {
2930
ConnectionOptions,
@@ -42,6 +43,4 @@ export interface PoolConnection extends BasePoolConnection {}
4243
export interface Pool extends BasePool {}
4344
export interface PoolCluster extends BasePoolCluster {}
4445
export interface Query extends BaseQuery {}
45-
export interface Prepare extends BasePrepare {}
46-
47-
export function createServer(handler: (conn: BaseConnection) => any): Server;
46+
export interface Prepare extends BasePrepare {}

typings/mysql/lib/Connection.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ declare class Connection extends EventEmitter {
271271
on(event: string, listener: Function): this;
272272

273273
rollback(callback: (err: Query.QueryError | null) => void): void;
274+
275+
execute(sql: string, values: Array<any>, cb: (err: any, rows: Array<any>, fields: Array<any>) => any): any;
276+
277+
unprepare(sql: string): any;
278+
279+
serverHandshake(args: any): any;
274280
}
275281

276282
export = Connection;

typings/mysql/lib/Pool.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ declare class Pool extends EventEmitter {
6161
on(event: string, listener: Function): this;
6262
on(event: 'connection', listener: (connection: PoolConnection) => any): this;
6363

64-
promise(promiseImpl?: any): any
64+
promise(promiseImpl?: any): any;
6565
}
6666

6767
export = Pool;

typings/mysql/lib/protocol/packets/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import RowDataPacket = require('./RowDataPacket');
44
import FieldPacket = require('./FieldPacket');
55
import Field = require('./Field');
66
import ResultSetHeader = require('./ResultSetHeader');
7+
import OkPacketParams = require('./params/OkPacketParams');
8+
import ErrorPacketParams = require('./params/ErrorPacketParams');
79

810
export {
911
OkPacket,
1012
RowDataPacket,
1113
FieldPacket,
1214
Field,
13-
ResultSetHeader
15+
ResultSetHeader,
16+
OkPacketParams,
17+
ErrorPacketParams
1418
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare interface ErrorPacketParams {
2+
message?: string;
3+
code?: number | string;
4+
}
5+
6+
export = ErrorPacketParams;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
declare interface OkPacketParams {
2+
affectedRows?: number;
3+
insertId?: number;
4+
serverStatus?: number;
5+
warningCount?: number;
6+
message?: string;
7+
}
8+
9+
export = OkPacketParams;

0 commit comments

Comments
 (0)