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

Typescript: Pool Cluster Typing Mismatch #1991

Closed
JacobBanghart opened this issue May 4, 2023 · 4 comments
Closed

Typescript: Pool Cluster Typing Mismatch #1991

JacobBanghart opened this issue May 4, 2023 · 4 comments

Comments

@JacobBanghart
Copy link

I am working in a typescript node project and running into a interface mismatch. If you clone https://github.com/JacobBanghart/Mysql2PoolClusterIssue and npm i you will see that there are 2 issues with the typings for PoolClusters.

First: uri is not a valid as a property to pass.
This can be adjusted by one of 2 ways. Either add the property to PoolOptions or better yet to Connection.ConnectionOptions as an optional property.

Secondly: PoolCluster.of returns a type of PoolCluster which is actually a PoolNamespace.

I can open a pr for these items if you would like.

@adam-farhi
Copy link

adam-farhi commented Jun 1, 2023

if I’m not mistaken this is the correct type

declare class PromisePoolCluster extends EventEmitter {

    config: PoolCluster.PoolClusterOptions;

    add(config: PoolCluster.PoolClusterOptions): Promise<void>;
    add(group: string, config: PoolCluster.PoolClusterOptions): Promise<void>;

    end(): Promise<void>;

    getConnection(): Promise<PoolConnection>;
    getConnection(group: string): Promise<PoolConnection>;
    getConnection(group: string): Promise<PoolConnection>;

    of(pattern: string, selector?: string): PromisePoolCluster;

    on(event: string, listener: Function): this;
    on(event: 'remove', listener: (nodeId: number) => void): this;
    on(event: 'connection', listener: (connection: PoolConnection) => void): this;
}

@sidorares see:
#2035

@wellwelwel

This comment was marked as resolved.

@wellwelwel

This comment was marked as resolved.

@wellwelwel
Copy link
Collaborator

wellwelwel commented Jul 9, 2023

After version ^3.4.1 you can follow these examples:

  • for callbacks:

    const poolCluster = mysql.createPoolCluster();
    poolCluster.add('cluster1', uriAccess);
    poolCluster.add('cluster2', access);
    /** execute */
    {
    const conn = poolCluster.of('cluster1');
    /** Overload: execute(sql, () => {}}) */
    conn.execute(sql, (err, result, fields) => {
    console.log(err, result, fields);
    });

  • for promise-based:

    const poolCluster = mysql.createPoolCluster();
    poolCluster.add('cluster1', uriAccess);
    poolCluster.add('cluster2', access);
    /** execute */
    (async () => {
    const conn = poolCluster.of('cluster1');
    {
    /** Overload: execute(sql) */
    const [results, fields] = await conn.execute(sql);
    console.log(results, fields);
    }


I'm closing this Issue, but feel free to ask anything 🙋🏻‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants