Registry / database / chain-mysql-builder

chain-mysql-builder

JSON →
library0.1.2jsnpmunverified

A lightweight, chainable MySQL query builder for Node.js, version 0.1.2. Designed as an alternative to complex ORM query builders, it uses method chaining to construct SQL statements. Currently only supports MySQL, with a simple API including select, where, whereIn, whereBetween, joins, and order by. Not actively maintained; limited functionality compared to Knex or Sequelize.

npm install chain-mysql-builder
INSTALL
IMPORT
SIG · CHAIN-MYSQL-BUILDE
C
chain-mysql-builder
databasejavascriptv0.1.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.

Builder
const Builder = require('chain-mysql-builder');
import Builder from 'chain-mysql-builder';
Package uses CommonJS; no default export for ESM.
new Builder()
const query = new Builder('table_name');
const query = Builder('table_name');
Constructor must be called with 'new'.
toSql()
const sql = new Builder('users').all().toSql();
const sql = new Builder('users').all().toString();
Use 'toSql()' to get SQL string, not 'toString()'.

Shows chainable where with OR grouping and outputting SQL string for use with mysql package.

const Builder = require('chain-mysql-builder'); let query = new Builder('users'); let sql = query.where('name', '=', 'Haven').orWhere(function(q) { q.where('age', '>', 30).where('gender', 'female'); }).toSql(); console.log(sql); // select * from users where name = 'Haven' or ( age > 30 and gender = female ) // Use with mysql driver const mysql = require('mysql'); const connection = mysql.createConnection({ host: 'localhost', user: 'root', password: process.env.DB_PASS ?? '' }); connection.query(sql, (err, results) => { if (err) throw err; console.log(results); }); connection.end();
Debug
Known issues
breakingUnescaped user input in where clause can lead to SQL injection.
fix
Manually escape inputs using mysql.escape() or use parameterized queries with the driver.
affects: <=0.1.2
gotchaAll method names are lowercase; camelCase like 'whereIn' is not supported.
fix
Use 'wherein' instead of 'whereIn'.
affects: <=0.1.2
gotchaThe 'where' and 'orWhere' methods expect operator as string; default operator is '=' for two arguments.
fix
Use three arguments to specify operator: where('col', '>', 5).
affects: <=0.1.2
gotchaSelect fields: 'all()' and 'get()' ignore any previously set 'select()'.
fix
Use 'get()' with array argument or 'select()' alone.
affects: <=0.1.2
deprecatedPackage is not actively maintained; last update 4 years ago. No TypeScript types.
fix
Consider migrating to Knex or Sequelize for active development and TypeScript support.
affects: >=0.0.0
Errors
Common errors & fixes
Error: chain-mysql-builder is not a constructor
Using import syntax instead of require, or missing 'new' keyword.
fix
const Builder = require('chain-mysql-builder'); const query = new Builder('table');
TypeError: query.whereIn is not a function
Method name is 'wherein' (all lowercase).
fix
Use .wherein('col', [1,2,3]) instead of .whereIn(...).
TypeError: query.all(...).toSql is not a function
Forgetting to call toSql() or calling it before all() chain.
fix
Ensure chain ends with .toSql(): new Builder('t').all().toSql();
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
chain-mysql-builder — npm install chain-mysql-builder · libregistry