npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

time-machine-js-plugin-mysql2

v1.0.0

Published

MySQL2 connection pool patcher for time-machine-js

Readme

time-machine-js-plugin-mysql2

An adapter to synchronize mysql2 promise pools with the time-machine-js and time-machine-js-plugin-express mocking flow. It automatically intercepts pool acquisitions to mock the database session's internal clock via SET TIMESTAMP = ?.

Installation

npm install time-machine-js-plugin-mysql2 time-machine-js

Usage (with Express Plugin)

If you are using the time-machine-js-plugin-express per-request integration, you should export the timeMachineStore from the Express plugin and pass it to the MySQL patcher.

This ensures that concurrent Node.js requests querying the database simultaneously are mocked perfectly in isolation without overlapping.

import mysql from "mysql2/promise";
import { patchMysql2Pool } from "time-machine-js-plugin-mysql2";
// Import the AsyncLocalStorage store exposed by the express plugin
import { timeMachineStore } from "time-machine-js-plugin-express";

const pool = mysql.createPool({
  host: "localhost",
  user: "root",
  database: "test",
});

// Patch the pool!
patchMysql2Pool(pool, timeMachineStore);

// Now, ANY time you checkout a connection from the pool inside an Express route,
// the server will automatically execute `SET TIMESTAMP = <Target Time>` BEFORE your query runs.
export default pool;

Usage (Global Only)

If you are not using Express, or are only relying on the .env fallback mapping TIME_MACHINE_TRAVEL_TO, you can simply patch the pool without providing a store. The patcher will automatically respect the global mocked state of time-machine-js.

import mysql from 'mysql2/promise';
import { patchMysql2Pool } from 'time-machine-js-plugin-mysql2';
// Requires time-machine-js to have been initialized globally!

const pool = mysql.createPool({ ... });
patchMysql2Pool(pool);

Important Warning

This library hooks into pool.getConnection(). Calls routed through pool.query() internally use pool.getConnection(), meaning they are natively covered by this patch.

However, if you create a single standalone connection (e.g. mysql.createConnection()), this plugin will NOT mock it. You must use a database pool.

License

MIT