-
-
Notifications
You must be signed in to change notification settings - Fork 625
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: update pool cluster of to use pool namespace #2036
Conversation
@JacobBanghart, in Just a basic test for each import way:
import mysql from 'mysql2';
const poolCluster = mysql.createPoolCluster();
poolCluster.add('MY_CLUSTER', {
host: '',
user: '',
password: '',
database: '',
});
// from: getConnection
{
poolCluster.getConnection('MY_CLUSTER', (err, conn) => {
conn.query('SELECT * FROM `table`;', (err, rows) => {
console.log(rows);
});
});
}
// from: of
{
const MY_CLUSTER = poolCluster.of('MY_CLUSTER');
MY_CLUSTER.query('SELECT * FROM `table`;', (err, rows) => {
console.log(rows);
});
}
import mysql from 'mysql2/promise';
(async () => {
const poolCluster = mysql.createPoolCluster();
poolCluster.add('MY_CLUSTER', {
host: '',
user: '',
password: '',
database: '',
});
// from: getConnection
{
const MY_CLUSTER = await poolCluster.getConnection('MY_CLUSTER');
const [rows] = await MY_CLUSTER.query('SELECT * FROM `table`;');
console.log(rows);
}
// from: of
{
const MY_CLUSTER = poolCluster.of('MY_CLUSTER');
const [rows] = await MY_CLUSTER.query('SELECT * FROM `table`;');
console.log(rows);
}
})();
If these changes are compatible with both import methods, I think basic tests could be created to ensure that every new change respects the basic usage of the Currently, this tests covers the most common cases of
|
@wellwelwel would you like to join as a co-maintainer? Happy to give you write permissions |
pool_cluster.js was out of sync with the typing and returns a pool namespace rather than a self reference pool cluster
So I had issues getting your second example to work on the latest version. It is having other issues unrelated to my change. But thanks for pointing out the relation to the index.d.ts. It seems more practical to place this as a part of the namespace definition. Then I do not modify anything but raw types and use an interface instead. The biggest disadvantage that I see to this is that you are not directly exporting the PoolNamespace for usage, but I can not think of a given use case for exporting it. |
@sidorares, It would be a pleasure. If you prefer, I can reach out to you via email or a most convenient way for you.
|
@JacobBanghart, when you do it in PoolCluster.d.ts: export interface PoolNamespace {
getConnection(callback: (err: NodeJS.ErrnoException | null, connection: PoolConnection) => any): void;
// ...
}
// ...
declare class PoolCluster extends EventEmitter {
of(pattern: string, selector?: string): PoolCluster.PoolNamespace;
// ...
} Naturally this will affect both You can compare these "import" differences, by example, looking at how it works for Line 89 in db91252
And how it changes for Line 91 in db91252
Then, adapting how it would be for the I understand that you didn't modify the The errors in my If you don't mind, I can help you with this 🙋🏻♂️ |
@wellwelwel small suggestion - when you link a code line, please link to a commit, not to a branch head ( press |
Closing in favor of #2084. |
pool_cluster.js was out of sync with the typing and returns a pool namespace rather than a self-reference pool cluster
fixes: #1991
This should fix one of the issues. There are some additional fixes that can be made such as having more dedicated typing for the union types.