Skip to content

Commit

Permalink
fix: move missing options to ConnectionOptions (#2288)
Browse files Browse the repository at this point in the history
* fix: move `enableKeepAlive` and `keepAliveInitialDelay` options to `ConnectionOptions`

* ci(types): enableKeepAlive and keepAliveInitialDelay
  • Loading branch information
wellwelwel committed Nov 21, 2023
1 parent 8831e09 commit 5cd7639
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 16 deletions.
@@ -0,0 +1,35 @@
import { mysql, mysqlp } from '../index.js';

// Callback
(() => {
const poolOptions: mysql.PoolOptions = {
enableKeepAlive: true,
keepAliveInitialDelay: 0,
}

const connectionOptions: mysql.ConnectionOptions = {
enableKeepAlive: true,
keepAliveInitialDelay: 0,
}

mysql.createConnection(connectionOptions);
mysql.createPool(poolOptions);
mysql.createPoolCluster().add(poolOptions);
})();

// Promise
(() => {
const poolOptions: mysqlp.PoolOptions = {
enableKeepAlive: true,
keepAliveInitialDelay: 0,
}

const connectionOptions: mysqlp.ConnectionOptions = {
enableKeepAlive: true,
keepAliveInitialDelay: 0,
}

mysqlp.createConnection(connectionOptions);
mysqlp.createPool(poolOptions);
mysqlp.createPoolCluster().add(poolOptions);
})();
30 changes: 24 additions & 6 deletions typings/mysql/lib/Connection.d.ts
Expand Up @@ -258,6 +258,16 @@ export interface ConnectionOptions {
*/
rowsAsArray?: boolean;

/**
* Enable keep-alive on the socket. (Default: true)
*/
enableKeepAlive?: boolean;

/**
* If keep-alive is enabled users can supply an initial delay. (Default: 0)
*/
keepAliveInitialDelay?: number;

charsetNumber?: number;

compress?: boolean;
Expand Down Expand Up @@ -312,22 +322,30 @@ declare class Connection extends QueryableBase(ExecutableBase(EventEmitter)) {
| RowDataPacket[]
| OkPacket
| OkPacket[]
| ResultSetHeader
| ResultSetHeader,
>(
sql: string,
callback?: (err: QueryError | null, result: T, fields: FieldPacket[]) => any
callback?: (
err: QueryError | null,
result: T,
fields: FieldPacket[],
) => any,
): Query;
static createQuery<
T extends
| RowDataPacket[][]
| RowDataPacket[]
| OkPacket
| OkPacket[]
| ResultSetHeader
| ResultSetHeader,
>(
sql: string,
values: any | any[] | { [param: string]: any },
callback?: (err: QueryError | null, result: T, fields: FieldPacket[]) => any
callback?: (
err: QueryError | null,
result: T,
fields: FieldPacket[],
) => any,
): Query;

beginTransaction(callback: (err: QueryError | null) => void): void;
Expand All @@ -338,7 +356,7 @@ declare class Connection extends QueryableBase(ExecutableBase(EventEmitter)) {

changeUser(
options: ConnectionOptions,
callback?: (err: QueryError | null) => void
callback?: (err: QueryError | null) => void,
): void;

end(callback?: (err: QueryError | null) => void): void;
Expand All @@ -363,7 +381,7 @@ declare class Connection extends QueryableBase(ExecutableBase(EventEmitter)) {

prepare(
sql: string,
callback?: (err: QueryError | null, statement: PrepareStatementInfo) => any
callback?: (err: QueryError | null, statement: PrepareStatementInfo) => any,
): Prepare;

unprepare(sql: string): PrepareStatementInfo;
Expand Down
10 changes: 0 additions & 10 deletions typings/mysql/lib/Pool.d.ts
Expand Up @@ -37,16 +37,6 @@ export interface PoolOptions extends ConnectionOptions {
* is no limit to the number of queued connection requests. (Default: 0)
*/
queueLimit?: number;

/**
* Enable keep-alive on the socket. (Default: true)
*/
enableKeepAlive?: boolean;

/**
* If keep-alive is enabled users can supply an initial delay. (Default: 0)
*/
keepAliveInitialDelay?: number;
}

declare class Pool extends QueryableBase(ExecutableBase(EventEmitter)) {
Expand Down

0 comments on commit 5cd7639

Please sign in to comment.