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 export
✓ const DB = require('alien-node-mysql-utils')(dbPool);
✗ const { query } = require('alien-node-mysql-utils');
The package exports a function that must be called with a mysql connection pool. It returns an object with methods query, lookup, etc.
query
✓ const { query } = require('alien-node-mysql-utils')(dbPool);
✗ const query = require('alien-node-mysql-utils').query;
Methods are returned only after invoking the exported function with a pool.
querySafe
✓ const { querySafe } = require('alien-node-mysql-utils')(dbPool);
✗ const querySafe = require('alien-node-mysql-utils/querySafe');
Subpath imports are not supported; all methods come from the same call.
Shows how to instantiate with a mysql pool and use query, querySafe, lookup, lookupSafe.
const mysql = require('mysql');
const pool = mysql.createPool({
host: 'localhost',
user: 'root',
password: '',
database: 'test'
});
const DB = require('alien-node-mysql-utils')(pool);
// query: returns array of rows, rejects if none
DB.query(['SELECT * FROM users WHERE active = ?', [1]])
.then(rows => console.log('Users:', rows))
.catch(err => console.error('Error:', err));
// querySafe: returns empty array if no rows
DB.querySafe(['SELECT * FROM users WHERE active = ?', [1]])
.then(rows => console.log('Users (safe):', rows))
.catch(err => console.error('Error:', err));
// lookup: returns one row object, rejects if none
DB.lookup(['SELECT * FROM users WHERE id = ?', [1]])
.then(user => console.log('User:', user))
.catch(err => console.error('Error:', err));
// lookupSafe: returns undefined if none
DB.lookupSafe(['SELECT * FROM users WHERE id = ?', [999]])
.then(user => console.log('User (safe):', user))
.catch(err => console.error('Error:', err));
Errors
Common errors & fixes
TypeError: require(...) is not a function
Imported module without calling it with a pool.
fixUse const DB = require('alien-node-mysql-utils')(pool); Cannot read property 'query' of undefined
Tried to destructure methods without invoking the export first.
fixCorrectly instantiate: const { query } = require('alien-node-mysql-utils')(pool); Error: No records found
query or lookup used when no rows exist.
fixUse querySafe or lookupSafe instead if no result is acceptable.
Audit
Dependencies
ramdarequiredUsed for function currying
mysqlrequiredPeer dependency for MySQL driver