Skip to content

Commit 120757f

Browse files
fix: connection types mismatched code
This fixes a number of small type errors compared to the underlying code. This is likely a breaking change for some users as it would have required some working around. Should fix sidorares#3238 and sidorares#2667
1 parent d48f143 commit 120757f

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

promise.d.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import {
77
FieldPacket,
88
QueryOptions,
99
ConnectionOptions,
10+
Connection as CoreConnection,
1011
PoolOptions,
1112
PoolClusterOptions,
1213
Pool as CorePool,
14+
PoolConnection as CorePoolConnection,
1315
} from './index.js';
1416
import { ExecutableBase as ExecutableBaseClass } from './typings/mysql/lib/protocol/sequences/promise/ExecutableBase.js';
1517
import { QueryableBase as QueryableBaseClass } from './typings/mysql/lib/protocol/sequences/promise/QueryableBase.js';
@@ -42,6 +44,8 @@ export interface PreparedStatementInfo {
4244
export interface Connection extends QueryableAndExecutableBase {
4345
config: ConnectionOptions;
4446

47+
connection: CoreConnection;
48+
4549
threadId: number;
4650

4751
connect(): Promise<void>;
@@ -78,17 +82,16 @@ export interface Connection extends QueryableAndExecutableBase {
7882

7983
export interface PoolConnection extends Connection {
8084
release(): void;
81-
connection: Connection;
8285
}
8386

84-
export interface Pool extends Connection {
87+
export interface Pool extends Pick<CorePool, 'execute' | 'query' | 'escape' | 'escapeId' | 'format'> {
8588
getConnection(): Promise<PoolConnection>;
8689

8790
releaseConnection(connection: PoolConnection): void;
8891

89-
on(event: 'connection', listener: (connection: PoolConnection) => any): this;
90-
on(event: 'acquire', listener: (connection: PoolConnection) => any): this;
91-
on(event: 'release', listener: (connection: PoolConnection) => any): this;
92+
on(event: 'connection', listener: (connection: CorePoolConnection) => any): this;
93+
on(event: 'acquire', listener: (connection: CorePoolConnection) => any): this;
94+
on(event: 'release', listener: (connection: CorePoolConnection) => any): this;
9295
on(event: 'enqueue', listener: () => any): this;
9396

9497
end(): Promise<void>;

typings/mysql/lib/Connection.d.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ export interface ConnectionOptions {
335335
jsonStrings?: boolean;
336336
}
337337

338-
declare class Connection extends QueryableBase(ExecutableBase(EventEmitter)) {
338+
declare class BaseConnection extends QueryableBase(ExecutableBase(EventEmitter)) {
339339
config: ConnectionOptions;
340340

341341
threadId: number;
@@ -414,8 +414,6 @@ declare class Connection extends QueryableBase(ExecutableBase(EventEmitter)) {
414414

415415
serverHandshake(args: any): any;
416416

417-
promise(promiseImpl?: PromiseConstructor): PromiseConnection;
418-
419417
ping(callback?: (err: QueryError | null) => any): void;
420418

421419
writeOk(args?: OkPacketParams): void;
@@ -431,4 +429,7 @@ declare class Connection extends QueryableBase(ExecutableBase(EventEmitter)) {
431429
sequenceId: number;
432430
}
433431

434-
export { Connection };
432+
declare class Connection extends BaseConnection {
433+
promise(promiseImpl?: PromiseConstructor): PromiseConnection;
434+
}
435+
export { Connection, BaseConnection };

typings/mysql/lib/Pool.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ declare class Pool extends QueryableBase(ExecutableBase(EventEmitter)) {
6363

6464
promise(promiseImpl?: PromiseConstructor): PromisePool;
6565

66+
format(sql: string, values?: any | any[] | { [param: string]: any }): string;
67+
68+
escape(value: any): string;
69+
70+
escapeId(value: string | string[]): string;
71+
escapeId(values: string[]): string;
72+
6673
config: PoolOptions;
6774
}
6875

typings/mysql/lib/PoolConnection.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Connection } from './Connection.js';
1+
import { Connection, BaseConnection } from './Connection.js';
22
import { Pool as PromisePool } from '../../../promise.js';
33

4-
declare class PoolConnection extends Connection {
4+
declare class PoolConnection extends BaseConnection {
55
connection: Connection;
66
release(): void;
77
promise(promiseImpl?: PromiseConstructor): PromisePool;

0 commit comments

Comments
 (0)