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.
mq
✓ const mq = require('mq-node')({ host: 'localhost', user: 'root', password: '', database: 'test' });
✗ const mq = require('mq-node');
The module exports a function that must be called with connection config; it returns the query builder instance.
insert
✓ mq.insert('table', { col: 'val' }, callback);
✗ mq.insert('table', { col: 'val' });
Callback is optional but needed to get results. No promise support.
select
✓ mq.select({ from: 'table', where: { id: 1 } }, callback);
✗ mq.select('table', { where: { id: 1 } }, callback);
First argument must be an object with properties like 'from', 'where', etc. Not a table name.
Demonstrates basic INSERT, SELECT, UPDATE, DELETE using JSON query objects with callbacks.
const mq = require('mq-node')({
host : 'localhost',
user : 'root',
password : '',
database : 'test'
});
// Insert
mq.insert('users', { name: 'John', age: 30 }, function(err, result) {
if (err) throw err;
console.log('Inserted ID:', result.insertId);
});
// Select
mq.select({
from: 'users',
where: { name: 'John' },
cols: ['name', 'age']
}, function(err, rows) {
if (err) throw err;
console.log('Rows:', rows);
});
// Update
mq.update('users', { age: 31 }, { name: 'John' }, function(err, result) {
if (err) throw err;
console.log('Updated rows:', result.affectedRows);
});
// Delete
mq.delete('users', { name: 'John' }, function(err, result) {
if (err) throw err;
console.log('Deleted rows:', result.affectedRows);
});
Errors
Common errors & fixes
Cannot read property 'query' of undefined
require('mq-node') returns a function, not the query builder, if not called with config.
fixconst mq = require('mq-node')(config); then use mq.query(...) TypeError: callback is not a function
Select/insert/update/delete called without a callback function.
fixAlways provide a callback: mq.select({...}, function(err, res) {...}); ER_PARSE_ERROR: You have an error in your SQL syntax
Invalid JSON structure passed to query builders (e.g., missing 'from' property).
fixEnsure the object passed to select/insert/update/delete has correct keys.
Audit
Dependencies
mysqlrequiredUses 'mysql' as the underlying MySQL client for connections and query execution.