sidorares / sidorares/node-mysql2

A pool should be able to hand out both promise/non-promise wrapped connections

Open
#809 3 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

In several of my applications built using node-mysql2, I maintain a pool of connections in one module:

/db.js
import mysql from 'mysql2';
export const pool = mysql.createPool(mysqlURI);

In another module, I then use the pool to retrieve a connection, for operating on the connection in streaming mode, so I do this:

/module1.js
let con = pool.getConnection()
con.query("SELECT ...")
.on('result', ...)

In another module, I wish to use the pool to retrieve a connection, for operating on the connection in promise mode, so i'd like to do this:

/module2.js
let con = pool.getConnectionPromise()
con.query("SELECT ...")
.then( .... )

Unfortunately, because the pool only allows you to retrieve either a promise or non-promise wrapped connection, I need to create 2 different pools:

/db.js
import mysql from 'mysql2';
export const pool = mysql.createPool(mysqlURI);
export const poolPromise = mysql.createPoolPromise(mysqlURI);

It would be helpful if the non-promise pool allowed you to call getConnectionPromise, or queryPromise. Not all code is suited for use with promises, and maintaining two pools isn't ideal.

IMO their should only be one type of pool and you should decide when using it whether you want a promise wrapped connection/query or not

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

Trace the pool and connection APIs described in /db.js, /module1.js, and /module2.js, starting with getConnection and the promise-pool alternative. Determine how promise wrapping is selected today and define done as one pool supporting both callback/streaming and promise-based retrieval without requiring two pools. Verify the behavior with the project's relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mysql, node.js, typescript
Domain
backend, databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 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.