Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: setQueryTimeout for mysql2DriverDialect #393

Merged
merged 4 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
joyc-bq marked this conversation as resolved.
Show resolved Hide resolved
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
joyc-bq marked this conversation as resolved.
Show resolved Hide resolved
.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) {
joyc-bq marked this conversation as resolved.
Show resolved Hide resolved
const timeout = wrapperQueryTimeout ?? props.get(WrapperProperties.WRAPPER_QUERY_TIMEOUT.name);
if (timeout) {
props.set(NodePostgresDriverDialect.QUERY_TIMEOUT_PROPERTY_NAME, timeout);
Expand Down