Registry / database / like-mysql

like-mysql

JSON →
library2.0.2jsnpmunverified

like-mysql is a simple, intuitive ORM for MySQL built on top of mysql2. Version 2.0.2 provides a promise-based API with automatic SQL query building for common operations like insert, select, update, delete, exists, and count. It supports transactions with a callback pattern and prepared statements by default. Key differentiators: minimal configuration, automatic WHERE handling, and integration with like-sql for query generation. Release cadence is low; the package has not seen updates since 2020. Compared to Sequelize or TypeORM, it offers a lightweight, no-frills experience with fewer features but lower complexity.

npm install like-mysql
INSTALL
IMPORT
SIG · LIKE-MYSQL
L
like-mysql
databasejavascriptv2.0.2
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.

default
const mysql = require('like-mysql')
import mysql from 'like-mysql'
Package does not ship ESM; use CommonJS require().
default
const mysql = require('like-mysql'); const db = mysql(...)
const db = new mysql(...)
mysql is a factory function, not a constructor. Do not use 'new'.
default
const mysql = require('like-mysql'); const db = mysql('127.0.0.1:3306', 'user', 'pass', 'db')
const db = mysql({host:'127.0.0.1', port:3306, user:'user', password:'pass', database:'db'})
Constructor expects positional arguments (host:port, user, password, database), not an options object.

Shows how to create a connection pool, wait for readiness, insert a row, select rows, and close the pool.

const mysql = require('like-mysql'); const db = mysql('127.0.0.1:3306', 'root', process.env.MYSQL_PASSWORD ?? '', 'myapp'); async function main() { await db.ready(); const insertId = await db.insert('users', { name: 'Alice', email: 'alice@example.com' }); console.log('Inserted id:', insertId); const users = await db.select('users', ['*'], 'email = ?', 'alice@example.com'); console.log('Users:', users); await db.end(); } main().catch(console.error);
Debug
Known issues
deprecatedPackage has not been updated since 2020; may not support modern MySQL versions or Node.js >= 14.
fix
Consider using a maintained alternative like Sequelize, TypeORM, or mysql2 directly.
affects: >=2.0.0
gotchaFactory function expects positional arguments (host:port, user, password, database); does not accept an options object.
fix
Use string arguments in order: 'host:port', 'user', 'password', 'database'. For socketPath, pass path as first argument.
affects: >=1.0.0
gotchaAutomatic WHERE detection may misinterpret certain strings; if the find argument does not start with 'ORDER BY', 'LIMIT', or 'GROUP BY', it is treated as a WHERE clause.
fix
Always prefix non-WHERE clauses with the appropriate keyword (e.g., 'ORDER BY ...').
affects: >=1.0.0
gotchaThe transaction callback receives a connection object (conn) but that object's methods are undocumented; they mirror db methods but are not fully typed.
fix
Use conn.insert, conn.select, etc. inside transaction callback as shown in README.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: mysql is not a function
Using ESM import syntax (import mysql from 'like-mysql') which is not supported.
fix
Use CommonJS require: const mysql = require('like-mysql');
Error: connect ECONNREFUSED 127.0.0.1:3306
MySQL server is not running or connection details are wrong.
fix
Ensure MySQL is running on the specified host:port, or provide correct credentials.
TypeError: db.ready is not a function
Calling ready() before the pool is created, or using wrong import method.
fix
Ensure you call mysql() to create db first, then await db.ready(). Check import is correct.
Error: ER_BAD_FIELD_ERROR: Unknown column '...' in 'field list'
Using a column name that does not exist in the table.
fix
Verify column names in your select/insert/update calls match the database schema.
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies
mysql2requiredMySQL driver for pool and connection management
like-sqlrequiredSQL query builder used internally
Agent activity
14 hits · last 30 days
node
12
Resources
like-mysql — npm install like-mysql · libregistry