sidorares / sidorares/node-mysql2

warn / error when promise wrapper functions are used with callback

Open
#998 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
4.4k
Forks
680
Avg merge
9h 7m
Merged PRs (30d)
59

Description

Looks like it's a common mistake, we should warn ( or maybe throw an error when promisified api method is used with a call back )

https://teratail.com/questions/118317

  const job = async () => {
    const conn = await pool.getConnection();

    await conn.query('SELECT * FROM hoge_1', (err, rows, fields) => {
      if (err) throw err;
      console.log(rows);
    });

    await conn.query('SELECT * FROM hoge_2', (err, rows, fields) => {
      conn.release();
      if (err) throw err;
      console.log(rows);
    });
  };

  await job();
  await pool.end();

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the promise wrapper used by conn.query and the callback-handling path shown in the example. Check how pool.getConnection and the promise API distinguish callback usage, then add coverage for the selected warning or error behavior and verify the example no longer passes silently.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, node.js, typescript
Domain
backend, database
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.