Skip to content

Commit

Permalink
query with timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
joyc-bq committed Feb 5, 2025
1 parent 7dd4ee2 commit df73f66
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions mysql/lib/dialect/mysql2_driver_dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export class MySQL2DriverDialect implements DriverDialect {
}
}

setQueryTimeout(props: Map<string, any>, sql?: any, wrapperConnectTimeout?: any) {
const timeout = wrapperConnectTimeout ?? props.get(WrapperProperties.WRAPPER_QUERY_TIMEOUT.name);
setQueryTimeout(props: Map<string, any>, sql?: any, wrapperQueryTimeout?: any) {
const timeout = wrapperQueryTimeout ?? props.get(WrapperProperties.WRAPPER_QUERY_TIMEOUT.name);
if (timeout && !sql[MySQL2DriverDialect.QUERY_TIMEOUT_PROPERTY_NAME]) {
sql[MySQL2DriverDialect.QUERY_TIMEOUT_PROPERTY_NAME] = Number(timeout);
}
Expand Down
19 changes: 11 additions & 8 deletions mysql/lib/dialect/mysql_database_dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,17 @@ export class MySQLDatabaseDialect implements DatabaseDialect {

async isClientValid(targetClient: ClientWrapper): Promise<boolean> {
try {
return await targetClient
.query("SELECT 1")
.then(() => {
return true;
})
.catch(() => {
return false;
});
return await ClientUtils.queryWithTimeout(
targetClient
.query("SELECT 1")
.then(() => {
return true;
})
.catch(() => {
return false;
}),
targetClient.properties
);
} 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>, wrapperQueryTimeout?: any) {
setQueryTimeout(props: Map<string, any>, sql?: 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 df73f66

Please sign in to comment.