sidorares / sidorares/node-mysql2
Releasing connections
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.4k
- Forks
- 680
- Avg merge
- 9h 7m
- Merged PRs (30d)
- 59
Description
Hello,
In the documentation, the way to release a connection from the pool is to use the callback version of getting a connection.
pool.getConnection(function(err, conn) {
// Do something with the connection
conn.query(/* ... */);
// Don't forget to release the connection when finished!
pool.releaseConnection(conn);
})
By looking at the source code, I noticed that the promisified pool implementation did not have releaseConnection implemented, which explains the code example in README.
Because I dont want to deal with callback after finding, this lib this seems like one of the only callback methods left. I wanted to find a work around without any wrapper. And, I was able to come up with this.
const poolPromise = pool.promise()
var connection = await poolPromise.getConnection()
await connection.beginTransaction()
// couple queries
await connection.commit()
connection.release()
Is there any downside to releasing the connection directly and bypassing the pool's release method?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the README connection examples and the promisified pool implementation mentioned in the issue, then compare how callback and promise connections are released. Done means the supported release behavior is clarified and the documentation no longer leaves the promisified API ambiguous.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, node.js, typescript
- Domain
- backend, databases
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100