Skip to content

Commit

Permalink
fix: setQueryTimeout for mysql2DriverDialect (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
joyc-bq authored Feb 6, 2025
1 parent 09f4931 commit acc06d6
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion common/lib/client_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface ClientWrapper {
readonly properties: Map<string, any>;
readonly id: string;

query(sql: any): Promise<any>;
query(sql: string): Promise<any>;

end(): Promise<void>;

Expand Down
7 changes: 4 additions & 3 deletions common/lib/mysql_client_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ export class MySQLClientWrapper implements ClientWrapper {
this.id = uniqueId("MySQLClient_");
}

query(sql: any): Promise<any> {
this.driverDialect.setQueryTimeout(this.properties, sql);
return this.client?.query(sql);
query(sql: string): Promise<any> {
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 common/lib/pg_client_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class PgClientWrapper implements ClientWrapper {
this.id = uniqueId("PgClient_");
}

query(sql: any): Promise<any> {
query(sql: string): Promise<any> {
return this.client?.query(sql);
}

Expand Down
2 changes: 1 addition & 1 deletion common/lib/pool_client_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class PoolClientWrapper implements ClientWrapper {
return this.end();
}

query(sql: any): Promise<any> {
query(sql: string): Promise<any> {
return this.client?.query(sql);
}

Expand Down
6 changes: 3 additions & 3 deletions mysql/lib/dialect/mysql2_driver_dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ 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] = timeout;
sql[MySQL2DriverDialect.QUERY_TIMEOUT_PROPERTY_NAME] = Number(timeout);
}
}

Expand Down
2 changes: 1 addition & 1 deletion mysql/lib/dialect/mysql_database_dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class MySQLDatabaseDialect implements DatabaseDialect {
try {
return await ClientUtils.queryWithTimeout(
targetClient
.query({ sql: "SELECT 1" })
.query("SELECT 1")
.then(() => {
return true;
})
Expand Down

0 comments on commit acc06d6

Please sign in to comment.