Registry / database / mysql-qb

mysql-qb

JSON →
library0.9.0jsnpmunverified

mysql-qb (version 0.9.0) is a MySQL query builder for Node.js that simplifies constructing SELECT (with joins), INSERT, UPDATE, and DELETE queries programmatically without raw SQL. It can be used as a standalone builder to generate SQL strings suitable for the mysql driver, or as an executor that manages connections and returns Promises. The package is pre-1.0 and updated frequently, targeting Node.js 4.1.2 to 6.3, and is not stable. Its key differentiator is offering both building and executing with Promise-based async flows, contrasting with the callback-oriented mysql driver. No TypeScript support is provided.

npm install mysql-qb
INSTALL
IMPORT
SIG · MYSQL-QB
M
mysql-qb
databasejavascriptv0.9.0
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.

select
var select = require('mysql-qb').select;
import { select } from 'mysql-qb';
Package uses CommonJS and has no default export. Named function 'select' is available as property of require().
QueryBuilder
var QueryBuilder = require('mysql-qb');
const QueryBuilder = require('mysql-qb').QueryBuilder;
The require returns the QueryBuilder constructor directly, not an object with a QueryBuilder property.
mysql-qb
var qb = require('mysql-qb');
const qb = require('mysql-qb').default;
Default import does not exist. The main export is a function (QueryBuilder) or object with static methods like select.

Demonstrates both builder mode (generates SQL string) and executor mode (creates connection and returns Promise) for a SELECT query.

var mysql = require('mysql'); var connection = mysql.createConnection({ host: 'localhost', user: 'root', password: '', database: 'test' }); connection.connect(); var qb = require('mysql-qb'); // As builder only var SQL = qb.select('id, name') .from('users') .where('status', 'active') .orderBy('created_at', 'DESC') .limit(10) .build(); console.log(SQL); // SELECT id, name FROM users WHERE status='active' ORDER BY created_at DESC LIMIT 10 // As executor with connection var QueryBuilder = require('mysql-qb'); var mqb = new QueryBuilder(connection); mqb.select('id, name') .from('users') .where('id', 1) .exec() .then(function(result) { console.log(result); }) .catch(function(err) { console.error(err); }); connection.end();
Debug
Known issues
gotchaThe package is pre-1.0 and updated frequently; breaking changes may occur without notice. Do not rely on stability.
fix
Pin to exact version in package.json and upgrade cautiously.
affects: <1.0.0
breakingThe engine requirement is Node.js >=4.1.2 and <=6.3. Using newer Node versions may cause unexpected behavior or errors.
fix
Use Node.js 6.3 or lower, or consider a maintained alternative like knex.
affects: 0.x
gotchaWhen using as executor with a connection object, if the connection state is 'disconnected', the builder will try to reconnect using stored config. This may fail silently if config is not available.
fix
Ensure the connection is active or pass config object instead of connection.
affects: all
deprecatedThe package has been inactive since 2017. No updates or fixes for known issues are forthcoming.
fix
Migrate to an actively maintained query builder like knex.
affects: >=0.7.0
gotchaThe builder returns promises when using exec(), but the mysql driver uses callbacks. Mixing patterns can be confusing.
fix
Always use .then() and .catch() on exec() calls, never mix with callbacks.
affects: all
Errors
Common errors & fixes
Cannot find module 'mysql-qb'
Package not installed or npm install failed due to engine constraints.
fix
Run 'npm install mysql-qb@0.9.0 --save' and ensure Node version is 4.1.2–6.3.
TypeError: qb.select is not a function
Incorrect import pattern, e.g., using ES6 import or destructuring incorrectly.
fix
Use 'var qb = require('mysql-qb');' then call qb.select(...).
Error: connect ECONNREFUSED 127.0.0.1:3306
MySQL server not running or wrong host/port in config.
fix
Start MySQL server, or provide correct host, port, user, and password in config.
Error: Cannot enqueue Query after invoking quit.
Connection was ended before executing the query.
fix
Move connection.end() after the exec() promise resolves.
Upgrade
Version history
0.9.0latest on npm
Audit
Dependencies
mysqloptionalRequired for connection and execution functionality when using the QueryBuilder as executor.
Agent activity
6 hits · last 30 days
node
6
Resources
mysql-qb — npm install mysql-qb · libregistry