Registry / testing / mysql-emulator

mysql-emulator

JSON →
library0.1.0jsnpmunverified

MySQL emulator that runs entirely in Node.js without a real MySQL server, designed for end-to-end testing. Current version 0.1.0 is in active development with known limitations (no RIGHT JOIN, no timezone support, partial INFORMATION_SCHEMA). It integrates with Sequelize 6+ and TypeORM 0.3+ via peer dependencies, supporting common SQL operations including SELECT, INSERT, UPDATE, DELETE, foreign key constraints, and basic functions. Unlike MySQL mock libraries that only intercept queries, this emulator parses and executes SQL internally, providing more realistic behavior for e2e tests.

npm install mysql-emulator
INSTALL
IMPORT
SIG · MYSQL-EMULATOR
M
mysql-emulator
testingjavascriptv0.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

query
import { query } from 'mysql-emulator'
const mysql = require('mysql-emulator');
ESM-only; no CommonJS support.
createConnection
import { createConnection } from 'mysql-emulator'
import createConnection from 'mysql-emulator'
Named export, not default.
getConnectionManager
import { getConnectionManager } from 'mysql-emulator'
TypeScript types included; use for managing multiple connections.

Creates a MySQL emulator connection, creates a table, inserts a row, and queries it, demonstrating basic SQL execution.

import { query, createConnection } from 'mysql-emulator'; async function main() { const conn = createConnection(); await conn.query('CREATE TABLE IF NOT EXISTS users (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255))'); await conn.query('INSERT INTO users (name) VALUES (?)', ['Alice']); const results = await query('SELECT * FROM users'); console.log(results); } main().catch(console.error);
Debug
Known issues
breakingRIGHT JOIN is not supported
fix
Rewrite queries using LEFT JOIN or other workarounds.
affects: <=0.1.0
deprecatedNo INFORMATION_SCHEMA tables are filled
fix
Avoid relying on INFORMATION_SCHEMA for introspection; use explicit schema queries.
affects: <=0.1.0
gotchaDefault ORDER may differ from real MySQL; always use ORDER BY when order matters
fix
Add explicit ORDER BY to your queries.
affects: all
gotchaColumn names may differ from real MySQL, e.g., `count(u.id)` becomes `COUNT(``u``.``id``)`
fix
Use column aliases to normalize names.
affects: all
gotchaNo timezone support; all date/time operations assume UTC
fix
Manually convert timezones in application logic.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'mysql-emulator'
Package not installed or not in node_modules
fix
Run npm install mysql-emulator
TypeError: mysql.createConnection is not a function
Using CommonJS require with an ESM-only package
fix
Use import syntax instead of require()
Error: RIGHT JOIN not implemented
Query uses RIGHT JOIN which is unsupported
fix
Rewrite query with LEFT JOIN
Error: Unknown column 'X' in 'field list'
Column name mismatch due to backtick handling
fix
Use consistent quoting or aliases
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
sequelizeoptionalPeer dependency for Sequelize integration; requires sequelize@>=6.0.0
typeormoptionalPeer dependency for TypeORM integration; requires typeorm@>=0.3.0
Agent activity
18 hits · last 30 days
node
14
Resources
mysql-emulator — npm install mysql-emulator · libregistry