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

chore: separate database dialect and driver dialect #235

Merged
merged 2 commits into from
Oct 30, 2024

Conversation

karenc-bq
Copy link
Contributor

@karenc-bq karenc-bq commented Oct 11, 2024

Summary

The database dialect class is a little convoluted right now. It contains methods that should are not relevant to the database and are more relevant to the target driver instead.
This PR separates the dialect classes into database and driver dialect.

This PR also implements the ClientWrapper interface via PgClientWrapper, MySQLClientWrapper and PoolClientWrapper. Prior to this change, the wrapper was passing ClientWrapper around, which contains no information about the underlying target client, the wrapper had to rely on under classes such as driver dialects and connection providers to determine which database method to call on the received ClientWrapper object. With these specific implementations, the wrapper is able to simply call ClientWrapper#end without having to worry about the driver specific implementation.

Description

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@karenc-bq karenc-bq force-pushed the refactor/driver-dialect branch from 0ccd6ea to 69dbd46 Compare October 11, 2024 19:32
@karenc-bq karenc-bq added the ready for review Pull requests that are ready to be reviewed label Oct 11, 2024
pg/lib/client.ts Outdated Show resolved Hide resolved
mysql/lib/client.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@sophia-bq sophia-bq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious on the reasoning behind the differing driver dialect names: why is it NodePostgresDriverDialect and MySql2DriverDialect?

@karenc-bq
Copy link
Contributor Author

Just curious on the reasoning behind the differing driver dialect names: why is it NodePostgresDriverDialect and MySql2DriverDialect?

Its the name of the target drivers we are using, node-postgres and mysql2

common/lib/driver_connection_provider.ts Outdated Show resolved Hide resolved
common/lib/driver_connection_provider.ts Outdated Show resolved Hide resolved
common/lib/driver_dialect/driver_dialect.ts Outdated Show resolved Hide resolved
@karenc-bq karenc-bq force-pushed the refactor/driver-dialect branch 5 times, most recently from f44af69 to 4de2262 Compare October 22, 2024 02:16
getDialectName(): string;
abort(targetClient: ClientWrapper): Promise<void>;
rollback(targetClient: ClientWrapper): Promise<any>;
connect(targetClient: any): Promise<any>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this latest update the function signature should be:

connect(props: Map<string, any>): Promise<any>;

}
}

connect(props: Map<string, any>): Promise<any> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the latest update connect should be returning the connected 'raw' targetClient of type any.
It probably needs to be async connect(...) {}

Please verify, but I think this function should look like this:

  async connect(props: Map<string, any>): Promise<any> {
    const targetClient: any =  createConnection(WrapperProperties.removeWrapperProperties(props));
    await targetClient
        .promise()
        .connect()
        .catch((error: any) => {
          throw error;
        });
    return targetClient;
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to call connect here

pg/lib/dialect/node_postgres_driver_dialect.ts Outdated Show resolved Hide resolved
@karenc-bq karenc-bq force-pushed the refactor/driver-dialect branch from 4de2262 to a6f20c3 Compare October 26, 2024 01:43
@karenc-bq karenc-bq force-pushed the refactor/driver-dialect branch from a6f20c3 to c7c630f Compare October 28, 2024 23:25
@@ -404,7 +404,7 @@ export class PluginService implements ErrorHandler, HostListProviderService {
}
}

async abortTargetClient(targetClient: ClientWrapper | undefined): Promise<void> {
async abortTargetClient(targetClient: ClientWrapper | undefined | null): Promise<void> {
if (targetClient) {
await this.getDriverDialect().abort(targetClient);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not to implement abort() in ClientWrapper classes (similar to rollback and destroy)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

targetClient might be a PoolClientWrapper. Can driver dialect abort such connection?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot about abort()

}

end(): Promise<void> {
return this.client.release();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return this.pool.release(this.cllient);

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be calling release on the target client not the pool.

@karenc-bq karenc-bq force-pushed the refactor/driver-dialect branch from cf3ba4e to 93d6109 Compare October 29, 2024 07:02
@karenc-bq karenc-bq force-pushed the refactor/driver-dialect branch from 93d6109 to b4a951c Compare October 29, 2024 23:35
@karenc-bq karenc-bq merged commit 9f0fa65 into main Oct 30, 2024
5 checks passed
@karenc-bq karenc-bq deleted the refactor/driver-dialect branch October 30, 2024 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review Pull requests that are ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants