Socket
Book a DemoInstallSign in
Socket

@7digital/mysql2-timeout

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@7digital/mysql2-timeout

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

4.0.1
latest
Source
npmnpm
Version published
Weekly downloads
4
-69.23%
Maintainers
3
Weekly downloads
 
Created
Source

MySQL2 Timeout

7digital

Test npm Node.js Version

A wrapper for mysql2 connection pool query to support connection acquiring and query timeout options.

Installation

npm install mysql2 @7digital/mysql2-timeout

Usage

Just use this instead of mysql2 and call connect passing acquireTimeout and defaultQueryTimeout 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

You can override the default query timeout on a per-query basis by specifying timeout when calling query with an object.

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',
    acquireTimeout: 2000,
    defaultQueryTimeout: 5000
  });

  await db.query('SELECT 1');

  await db.query({ sql: 'SELECT 2', timeout: 1000 });
}

Developing

Requirements:

  • Node.js (see package.json for version)
  • Docker
  • Docker Compose

make test

Spins up database and test containers, runs the tests once, and then stops the containers.

make watch

Spins up database and test containers, and runs the tests whenever the source or tests change.

Keywords

mysql

FAQs

Package last updated on 11 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.