Node Database Executor
raw JSON → 2.4.24 verified Sat Apr 25 auth: no javascript
A lightweight Node.js database query executor supporting both JSON-based queries (jsonQuery) and raw SQL queries. Version 2.4.24 is current stable, with frequent updates. It supports MySQL, MS SQL, PostgreSQL, and SQLite across multiple drivers (mysql, mssql, pg, sql.js). Key differentiator: provides a declarative JSON query language abstraction over raw SQL, reducing SQL injection risks and simplifying dynamic query building. Uses a promise-based API. Active development with regular releases.
Common errors
error TypeError: promise.executeQuery is not a function ↓
cause Using CJS require with missing .promise or using wrong import (e.g., import { executeQuery } directly).
fix
Use import { promise } from 'node-database-executor' then call promise.executeQuery()
error Cannot read property 'executeQuery' of undefined ↓
cause Forgetting to call .promise on the required module in CJS.
fix
const queryExecutor = require('node-database-executor').promise;
error ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' ↓
cause Missing or incorrect password or user in dbConfig.
fix
Verify dbConfig.user and dbConfig.password match your MySQL credentials.
Warnings
breaking Before v2.0, the library exported a promise chain instead of a promise object. Use promise.executeQuery now. ↓
fix Update code to use promise.executeQuery(config) instead of promise(config).then(...).
deprecated CJS require is deprecated. Use ESM import instead. ↓
fix Replace const x = require('node-database-executor') with import { promise } from 'node-database-executor'.
gotcha The dbConfig.password is required even for local development; omitting it throws a cryptic error. ↓
fix Always provide a password (can be empty string '' ) in dbConfig.
Install
npm install node-database-executor yarn add node-database-executor pnpm add node-database-executor Imports
- promise wrong
const promise = require('node-database-executor').promisecorrectimport { promise } from 'node-database-executor' - executeQuery wrong
executeQuery(config)correctpromise.executeQuery(config) - jsonQuery wrong
import { jsonQuery } from 'node-database-executor'correctimport { promise } from 'node-database-executor'; promise.executeQuery({query: jsonQueryObject})
Quickstart
import { promise } from 'node-database-executor';
async function run() {
const query = {
table: 'users',
select: ['id', 'name'],
where: { active: true }
};
const config = {
dbConfig: {
databaseType: 'mysql',
engine: 'InnoDB',
database: 'mydb',
host: 'localhost',
port: 3306,
user: 'root',
password: process.env.DB_PASS ?? '',
connectionLimit: 10,
acquireTimeout: 2000
},
query: query
};
try {
const result = await promise.executeQuery(config);
console.log(result);
} catch (err) {
console.error(err);
}
}
run();