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 MysqlJson = require('mysql-json');
const db = new MysqlJson(options);
✗ import MysqlJson from 'mysql-json'; // ESM not supported
The package exports a CommonJS class. Use require().
findByPrimaryKey
✓ db.findByPrimaryKey('table', 1, callback);
✗ db.findByPrimaryKey('table', '1', callback); // id parameter should be number, not string
Assumes primary key is numeric. String ids may not work correctly.
insert
✓ db.insert('table', {col: 'val'}, callback);
✗ db.insert('table', {col:7}, callback); // numeric values accepted but all values become strings due to JSON.stringify
May cause type coercion; numeric values are converted to strings.
Demonstrates full CRUD: insert, findByPrimaryKey, update, and delete using JSON objects.
const MysqlJson = require('mysql-json');
const db = new MysqlJson({ host:'127.0.0.1', user:'root', password:'root', database:'test' });
db.insert('users', {
name: 'Alice',
email: 'alice@example.com'
}, (err, res) => {
if (err) throw err;
console.log('Inserted:', res);
db.findByPrimaryKey('users', 1, (err, row) => {
if (err) throw err;
console.log('Found:', row);
db.update('users', { name: 'Alice Updated' }, { id: { operator: '=', value: 1 } }, (err) => {
if (err) throw err;
db.delete('users', { id: { operator: '=', value: 1 } }, (err) => {
if (err) throw err;
console.log('Deleted');
});
});
});
});
Errors
Common errors & fixes
TypeError: MysqlJson is not a constructor
Using import instead of require in a CommonJS environment.
fixUse require('mysql-json') instead of import. ER_BAD_FIELD_ERROR: Unknown column 'value' in 'where clause'
Conditions object formatted incorrectly; missing operator or nested incorrectly.
fixEnsure conditions are like {column: {operator: '=', value: 'val'}}. Cannot read property 'connect' of undefined
Database options missing or connection fails.
fixCheck host, user, password, database in options.
Audit
Dependencies
mysqlrequiredRequired to connect and query MySQL databases.