Miss any of our Open RFC calls?Watch the recordings here! »

@7digital/mysql2-timeout

2.0.0 • Public • Published

MySQL2 Timeout

7digital


Travis CI npm Node.js Version

A wrapper for mysql2 connection pool query to support acquireTimeout and queryTimeout options.

Installation

npm install mysql2 @7digital/mysql2-timeout

Usage

Just use this instead of mysql2 and call connect passing queryTimeout and acquireTimeout millisecond values. If not passed, each will default to 10 seconds. All other options will be passed directly to mysql2.

If connection aquisition times out, a DatabaseTimeout error will be thrown.

If querying times out, it will

  • kill the connection
  • attempt to kill the outstanding query in the background
  • throw a DatabaseTimeout error

This only exposes the mysql2 connection pool promise interface.

Example

const database = require('@7digital/mysql2-timeout');
 
async function main() {
  const db = await database.connect({
    host: 'localhost',
    user: 'root',
    database: 'test',
    queryTimeout: 5000,
    acquireTimeout: 2000
  });
 
  await db.query('SELECT 1');
}

Developing

docker-compose run test

Runs the tests once.

docker-compose run watch

Runs the tests when the source or tests change.

Install

npm i @7digital/mysql2-timeout

DownloadsWeekly Downloads

6

Version

2.0.0

License

ISC

Unpacked Size

4.85 kB

Total Files

4

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar