Registry / database / mysql-composer

mysql-composer

JSON →
library2.0.3jsnpmunverified

A lightweight Node.js MySQL query composer for building insert and update statements without an ORM. Version 2.0.3 simplifies dynamic SQL generation for scrapers and ETL tasks. Offers methods: insert, update, query, beginTransaction, rollback, commit. Unlike sequelize it does not require table modeling, but does not provide schema validation or migrations. Supports callbacks and optional promise wrappers. No active development since 2019.

npm install mysql-composer
INSTALL
IMPORT
SIG · MYSQL-COMPOSER
M
mysql-composer
databasejavascriptv2.0.3
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.

Composer
const Composer = require('mysql-composer')
import Composer from 'mysql-composer'
This package does not provide ESM exports; CommonJS require is required.
Composer
import mysql from 'mysql'; const connection = mysql.createConnection({...})
import mysql from 'mysql2'
The package is designed to work with the 'mysql' package, but 'mysql2' may also work if compatible.
composer.insert
composer.insert({table:'users', data:{name:'Tom'}}, callback)
composer.insert('users', {name:'Tom'}, callback)
The config object is required and must include table and data; passing string table name fails.
composer.update
composer.update({table:'users', data:{age:18}, where:'id=1'}, callback)
composer.update({table:'users', data:{age:18}}, callback)
Config.where is required. If omitted, update will error.

Demonstrates basic insert and update operations using Composer with mysql connection, including ignore flag and onDuplicateKeyUpdate.

const Composer = require('mysql-composer'); const mysql = require('mysql'); const connection = mysql.createConnection({ host: process.env.MYSQL_HOST ?? 'localhost', user: process.env.MYSQL_USER ?? 'root', password: process.env.MYSQL_PASSWORD ?? '', database: process.env.MYSQL_DATABASE ?? 'test' }); const composer = new Composer(connection); // Insert example composer.insert({ table: 'users', data: { name: 'Alice', age: 30 }, ignore: true, onDuplicateKeyUpdate: { age: 31 } }, function(err, result) { if (err) throw err; console.log('Inserted ID:', result.insertId); }, console.log); // Update example composer.update({ table: 'users', data: { age: function() { return 'age+1'; } }, where: 'id=1' }, function(err, result) { if (err) throw err; console.log('Rows affected:', result.affectedRows); }, console.log);
Debug
Known issues
breakingupdate config does not accept optional where; if omitted, update will throw error.
fix
Always include a 'where' property in the update config. Use '1' to update all rows.
affects: >=1.0.0
gotchainsert config.ignore defaults to true; if you want duplicate key errors, set ignore: false explicitly.
fix
Set ignore: false in the insert config to get errors on duplicate keys.
affects: >=1.0.0
gotchaCallback-style only; no built-in Promise support. Modern applications must manually wrap in Promise.
fix
Use util.promisify or create wrapper functions to use async/await.
affects: >=1.0.0
deprecatedThe package has not been updated since 2019 (v2.0.3). Unlikely to receive security updates or MySQL 8 compatibility fixes.
fix
Consider migrating to a maintained library like knex or mysql2 with prepared statements.
affects: >=2.0.0
breakingThe 'mysql-composer' package is CommonJS-only. Attempting ESM import will fail.
fix
Use require() instead of import. If using ES modules, create a dynamic import using createRequire.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: composer.insert is not a function
Composer constructor might not have been called with 'new'.
fix
Use 'new Composer(connection)' or ensure Composer is instantiated correctly.
Cannot read property 'query' of undefined
Connection object passed to Composer is undefined or null.
fix
Ensure mysql.createConnection returns a valid connection object and pass it to Composer.
ER_PARSE_ERROR: You have an error in your SQL syntax
Misconfigured where clause (e.g., missing quotes around strings) in update config.
fix
Use proper SQL syntax in the where string; for string values, enclose in single quotes.
TypeError: callback is not a function
Second argument to insert/update is not a function (e.g., omitted or undefined).
fix
Always provide a callback function as the second argument, even if logging.
Upgrade
Version history
2.0.3latest on npm
Audit
Dependencies
mysqloptionalPeer dependency for creating MySQL connections and executing queries
Agent activity
4 hits · last 30 days
node
4
Resources
mysql-composer — npm install mysql-composer · libregistry