sidorares / sidorares/node-mysql2

Commit with pool

Open
#1,391 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
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:

  1. At the beginning of the script: Create Pool
    this.pool = await mysql.createPool({ host: "xxxx.de", user: "xxx", password: "xxx", database: "xxx" });

  2. 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;
    }

  1. 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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.