Registry / database / mysql-warp

mysql-warp

JSON →
library0.2.9jsnpmunverified

A simple ORM for MySQL on Node.js, providing easy object-relational mapping and raw query execution. Current stable version is 0.2.9, last updated in 2014. The library wraps the mysql package and offers model definitions, CRUD operations, transaction support, and connection pooling. It is written in pure JavaScript and supports Node.js >=0.10.0. Differentiators include a straightforward API for defining models with type mappings, automatic table creation, and helper methods like `queryNumber`. However, it is largely unmaintained and lacks modern features like Promise support and TypeScript definitions.

npm install mysql-warp
INSTALL
IMPORT
SIG · MYSQL-WARP
M
mysql-warp
databasejavascriptv0.2.9
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 Warp = require('mysql-warp')
import Warp from 'mysql-warp'
The package uses CommonJS exports. There is no default export for ESM imports.
warp instance
const warp = Warp.create({ host: 'localhost', user: 'root', password: 'pass', database: 'test' })
const warp = new Warp({ host: 'localhost' })
Warp.create() is a factory method. Instantiating with 'new' will not work.
Model
const MyModel = warp.define('user', { name: String, age: Number })
const MyModel = new Model('user', { name: String })
Models are created via warp.define(), which returns a model constructor. Direct instantiation of Model is not supported.

This example shows how to create a warp instance, define a model, perform CRUD operations, and execute raw SQL queries using mysql-warp.

const Warp = require('mysql-warp'); const warp = Warp.create({ host: 'localhost', user: 'root', password: 'password', database: 'testdb' }); // Define a model const User = warp.define('users', { name: String, age: Number, email: String }); // Create a new user warp.connection.query('DROP TABLE IF EXISTS users', function(err) { if (err) throw err; User.create({ name: 'Alice', age: 30, email: 'alice@example.com' }, function(err, result) { if (err) throw err; console.log('Inserted user ID:', result.insertId); }); }); // Retrieve users User.find({ where: { age: 30 } }, function(err, users) { if (err) throw err; console.log('Users found:', users); }); // Raw query warp.query('SELECT * FROM users WHERE age > ?', [20], function(err, results) { if (err) throw err; console.log('Raw query results:', results); });
Debug
Known issues
deprecatedThe package has not been updated since 2014. It may not work with newer versions of Node.js or MySQL driver.
fix
Consider using an actively maintained ORM like Sequelize, TypeORM, or Knex.
affects: >=0.10.0
gotchaDefault charset is set to UTF8_GENERAL_CI. This may cause issues if your MySQL server uses a different charset.
fix
Ensure your MySQL server's charset matches or set charset explicitly in the configuration.
affects: >=0.0.1
gotchaThe library's 'defineTable' method is synchronous and may block the event loop for large table definitions.
fix
Define tables outside of high-traffic code paths or use raw queries for table creation.
affects: >=0.0.1
gotchaThe 'query' method uses callbacks only; no Promise support. This can lead to callback hell and difficulty handling errors.
fix
Wrap calls in Promises or use a library like 'util.promisify'.
affects: >=0.0.1
gotchaThe 'find' method with 'where' clause uses strict equality only (e.g., { name: 'John' }). It does not support operators like > or LIKE.
fix
Use raw queries for complex conditions.
affects: >=0.0.1
gotchaThe library's 'remove' (delete) method deletes records directly; there is no soft delete support built-in.
fix
Implement soft delete manually using an additional column.
affects: >=0.0.1
gotchaConnection pooling is not exposed directly; warp instance handles it internally. You cannot configure pool settings after initialization.
fix
Set pool options like 'connectionLimit' in the initial configuration.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: Warp.create is not a function
Attempted to use import syntax with CommonJS module.
fix
Use require('mysql-warp') instead of import.
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server
MySQL 8+ uses caching_sha2_password by default, which old mysql driver may not support.
fix
Use a newer MySQL driver or set default_authentication_plugin=mysql_native_password on the server.
Cannot read property 'insertId' of undefined
The create callback's result object is undefined because of missing connection or table.
fix
Ensure the table exists (use defineTable) and the warp configuration is correct.
Error: ER_NO_DEFAULT_FOR_FIELD: Field 'id' doesn't have a default value
The MySQL strict mode requires an id field with auto_increment or a default value.
fix
Include an 'id' field in the model definition with type 'Number' and let the library create it with auto_increment.
Error: connect ECONNREFUSED
MySQL server is not running or connection details are incorrect.
fix
Check that MySQL is running and the host/port/user/password are correct.
Upgrade
Version history
0.2.9latest on npm
Audit
Dependencies
mysqlrequiredDirect dependency for MySQL database connectivity.
Agent activity
5 hits · last 30 days
node
4
Resources
mysql-warp — npm install mysql-warp · libregistry