sidorares / sidorares/node-mysql2
Commit with pool
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.4k
- Forks
- 680
- Avg merge
- 9h 7m
- Merged PRs (30d)
- 59
Description
I have a script that is inserting tons of rows inside a mysql table. At the end of the script I do:
-
At the beginning of the script: Create Pool
this.pool = await mysql.createPool({ host: "xxxx.de", user: "xxx", password: "xxx", database: "xxx" }); -
Add all my entries: Insert each
const params = [entry.portal, entry.portalId || "", entry.title, entry.company || "", entry.region || "", entry.start || "", entry.duration || "", entry.jobType || "", entry.link, entry.description, entry.crawlTaskId, 'ACTIVE', entry.link];
const sql = 'INSERT INTO jobs SET portal=?, portalId=?, title=?, company=?, region=?, start=?, duration=?, jobType=?, link=?, description=?, crawlTaskId=?, status=?, linkHash=SHA2(?, 256)';
try {
await this.pool.execute(sql, params);
return true;
} catch (error) {
console.log(error);
return false;
}
- At the end of the script
Database.prototype.close = async function(){
await this.pool.commit();
await this.pool.close();
}
I get the error
(node:23600) UnhandledPromiseRejectionWarning: TypeError: this.pool.commit is not a function
Can I just remove the commit statement? And does a pool.close() flush all insertions to the database?
I'm a bit scared that if I do no commit some entries will be lost.
Best Regards
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 mentions mysql.createPool, pool.execute, pool.commit, and pool.close, but no repository files or tests. Start by locating the pool API and transaction documentation, then verify the documented behavior for committing inserts and closing a pool. Done means the supported pool lifecycle and commit behavior are clearly explained for this usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, node.js
- Domain
- database
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100