Registry / database / sql-wrap

sql-wrap

JSON →
library1.3.6-flow-fix-5jsnpmunverified

sql-wrap is a lightweight Node.js library (v1.3.6-flow-fix-5) that wraps node-mysql with a promise-based API, supporting Q promises alongside callbacks. It provides convenient shorthand methods like select(), insert(), update(), upsert(), and delete() that automatically generate SQL from objects, and includes streaming support via queryStream() and selectStream(). Key differentiators: automatic pagination with config objects, nested table join support via nestTables, and replication-aware pool cluster support for read/write separation. The library emits a 'result' event on queries and exposes an interface similar to node-mysql. Last updated in 2019, it is in maintenance mode with no recent activity.

npm install sql-wrap
INSTALL
IMPORT
SIG · SQL-WRAP
S
sql-wrap
databasejavascriptv1.3.6-flow-fix-5
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.

createNodeMySQL
import { createNodeMySQL } from 'sql-wrap'
const createNodeMySQL = require('sql-wrap')
The library exports a single named function createNodeMySQL. CommonJS require returns an object with that property.
createNodeMySQL (CommonJS)
const { createNodeMySQL } = require('sql-wrap')
const sqlWrap = require('sql-wrap'); const createNodeMySQL = sqlWrap.createNodeMySQL
The library uses named exports; destructuring works in both ESM and CJS.
Function itself
const sql = createNodeMySQL(pool)
const sql = new createNodeMySQL(pool)
createNodeMySQL is a factory function, not a constructor; do not use new.

Shows how to create a MySQL pool, instantiate sql-wrap, and use query, select, insert, update, delete, and queryStream methods.

import mysql from 'mysql'; import { createNodeMySQL } from 'sql-wrap'; const pool = mysql.createPool({ host: process.env.MYSQL_HOST ?? 'localhost', user: process.env.MYSQL_USER ?? 'root', password: process.env.MYSQL_PASSWORD ?? '', database: process.env.MYSQL_DATABASE ?? 'test' }); const sql = createNodeMySQL(pool); // Query using raw SQL sql.query('SELECT * FROM users WHERE age > ?', [18]) .then(rows => console.log(rows)) .catch(err => console.error(err)); // Convenience select sql.select('users', { status: 'active' }) .then(rows => console.log(rows)); // Insert a row sql.insert('users', { name: 'Alice', age: 30 }) .then(result => console.log('Inserted ID:', result.insertId)); // Update rows sql.update('users', { age: 31 }, { name: 'Alice' }) .then(result => console.log('Updated rows:', result.affectedRows)); // Delete rows sql.delete('users', { status: 'inactive' }) .then(result => console.log('Deleted rows:', result.affectedRows)); // Streaming query (returns a stream) sql.queryStream('SELECT * FROM large_table') .then(stream => { stream.on('data', row => console.log(row)); stream.on('end', () => console.log('done')); });
Debug
Known issues
deprecatedThis library is in maintenance mode; no updates since 2019. Consider using mysql2 with promise support or a more modern ORM like Knex.js.
fix
Migrate to mysql2/promise or use a query builder like Knex.
affects: >=1.3.6
gotchaWhereEqualsObject in select(), update(), delete() uses strict equality on values. For NULL comparisons, use { field: null } which becomes 'field IS NULL', but be aware that undefined values will be ignored (not added to WHERE clause).
fix
Use null explicitly for NULL checks; avoid undefined in where objects.
affects: >=1.0.0
gotchaselect() and selectOne() automatically add LIMIT 1 to selectOne but only if no LIMIT clause is present. This can cause unexpected results if the query already has a LIMIT.
fix
For custom LIMIT behavior, use query() instead of selectOne().
affects: >=1.0.0
gotchaThe queryStream() method returns a Promise that resolves to a stream, not the stream directly. Forgetting .then() will cause runtime errors.
fix
Use .then() or async/await to access the stream: const stream = await sql.queryStream(...);
affects: >=1.0.0
gotchaWhen using pagination in select() config, the pagination counts rows differently than raw LIMIT/OFFSET; ensure your use case aligns.
fix
Test pagination results; consider using query() with custom SQL for complex pagination.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: createNodeMySQL is not a function
Importing incorrectly; likely using default import instead of named import or destructuring from require().
fix
Use `import { createNodeMySQL } from 'sql-wrap'` or `const { createNodeMySQL } = require('sql-wrap')`.
Error: Cannot find module 'sql-wrap'
Package not installed or typo in package name.
fix
Run `npm install sql-wrap` and ensure node_modules contains it.
UnhandledPromiseRejectionWarning: Error: ER_ACCESS_DENIED_ERROR: Access denied for user
Invalid MySQL credentials or missing connection config.
fix
Verify MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD environment variables or connection parameters.
TypeError: pool.query is not a function
Passing a connection instead of a pool; createNodeMySQL expects a pool or poolCluster.
fix
Use `mysql.createPool(...)` and pass that pool to createNodeMySQL.
Upgrade
Version history
1.3.6-flow-fix-5latest on npm
Audit
Dependencies
mysqlrequiredRequired for creating MySQL connections/pools; sql-wrap wraps mysql.createPool and mysql.createPoolCluster.
qrequiredUsed for promise implementation; all methods return Q promises.
Agent activity
13 hits · last 30 days
node
10
Meta
2
OpenAI (training)
1
Resources