sidorares / sidorares/node-mysql2
How should I proper initiate my connections?
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.4k
- Forks
- 680
- Avg merge
- 9h 7m
- Merged PRs (30d)
- 59
Description
I'm porting a code and there are these two queries that are executed just after a connection is open.
SET CHARACTER SET utf8;
SET sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
I don't know if those queries could be set as parameter on node-mysql2 or how do I know if a connection I'm getting from pool is new.
What I'm doing at this moment is:
const conn = await pool.promise().getConnection();
if( !conn.connection.inited )
{
await conn.query( "SET CHARACTER SET utf8;\
SET sql_mode ='STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';" );
conn.connection.inited = true;
}
But I'm not ok with that.
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
The issue centers on pool.promise().getConnection() and the two SET statements; start by checking mysql2's pool and connection-initialization entry points for a supported way to apply session settings. Done means a reliable initialization path that works for both newly created and reused pooled connections.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, node.js
- Domain
- database
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 24/100