Skip to content

Commit

Permalink
fix: setQueryTimeout for mysql2DriverDialect
Browse files Browse the repository at this point in the history
  • Loading branch information
joyc-bq committed Feb 4, 2025
1 parent 98fcda0 commit 7dd4ee2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
5 changes: 3 additions & 2 deletions common/lib/mysql_client_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ export class MySQLClientWrapper implements ClientWrapper {
}

query(sql: any): Promise<any> {
this.driverDialect.setQueryTimeout(this.properties, sql);
return this.client?.query(sql);
const query = { sql: sql };
this.driverDialect.setQueryTimeout(this.properties, query);
return this.client?.query(query);
}

async queryWithTimeout(sql: string): Promise<any> {
Expand Down
2 changes: 1 addition & 1 deletion mysql/lib/dialect/mysql2_driver_dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class MySQL2DriverDialect implements DriverDialect {
setQueryTimeout(props: Map<string, any>, sql?: any, wrapperConnectTimeout?: any) {
const timeout = wrapperConnectTimeout ?? props.get(WrapperProperties.WRAPPER_QUERY_TIMEOUT.name);
if (timeout && !sql[MySQL2DriverDialect.QUERY_TIMEOUT_PROPERTY_NAME]) {
sql[MySQL2DriverDialect.QUERY_TIMEOUT_PROPERTY_NAME] = timeout;
sql[MySQL2DriverDialect.QUERY_TIMEOUT_PROPERTY_NAME] = Number(timeout);
}
}

Expand Down
19 changes: 8 additions & 11 deletions mysql/lib/dialect/mysql_database_dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,14 @@ export class MySQLDatabaseDialect implements DatabaseDialect {

async isClientValid(targetClient: ClientWrapper): Promise<boolean> {
try {
return await ClientUtils.queryWithTimeout(
targetClient
.query({ sql: "SELECT 1" })
.then(() => {
return true;
})
.catch(() => {
return false;
}),
targetClient.properties
);
return await targetClient
.query("SELECT 1")
.then(() => {
return true;
})
.catch(() => {
return false;
});
} catch (error) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion pg/lib/dialect/node_postgres_driver_dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class NodePostgresDriverDialect implements DriverDialect {
}
}

setQueryTimeout(props: Map<string, any>, sql?: any, wrapperQueryTimeout?: any) {
setQueryTimeout(props: Map<string, any>, wrapperQueryTimeout?: any) {
const timeout = wrapperQueryTimeout ?? props.get(WrapperProperties.WRAPPER_QUERY_TIMEOUT.name);
if (timeout) {
props.set(NodePostgresDriverDialect.QUERY_TIMEOUT_PROPERTY_NAME, timeout);
Expand Down

0 comments on commit 7dd4ee2

Please sign in to comment.