Registry / database / node-database-connectors

node-database-connectors

JSON →
library1.7.20jsnpmunverified

The `node-database-connectors` library provides a programmatic interface for converting structured JSON objects into database-specific SQL queries. It aims to abstract the direct SQL string construction process, offering a declarative approach to database interactions within Node.js applications. The library supports generating various SQL statements, including SELECT, INSERT, UPDATE, and DELETE, by interpreting JSON representations of tables, fields, aliases, join conditions, sorting, and filtering logic. Currently at version 1.7.20, it demonstrates a consistent release cadence with minor updates. Key differentiators include its focus on a JSON-based query language, its support for complex SQL operations and join conditions, and its ability to simplify application-level database logic by providing a structured, configuration-driven method for query construction.

npm install node-database-connectors
INSTALL
IMPORT
SIG · NODE-DATABASE-CONN
N
node-database-connectors
databasejavascriptv1.7.20
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

connectionIdentifier
import connectionIdentifier from 'node-database-connectors';
import { connectionIdentifier } from 'node-database-connectors';
The library primarily uses a default export for its main interface, which exposes the `identify` method. Attempting to destructure it as a named import will fail.
connectionIdentifier
const connectionIdentifier = require('node-database-connectors');
This is the standard CommonJS `require` pattern as demonstrated in the package's README and is suitable for Node.js environments.
objConnection.prepareQuery
const objConnection = connectionIdentifier.identify(sampleConfig); const query = objConnection.prepareQuery(jsonQuery);
The `identify` method on the default export returns a connection object, which then provides the `prepareQuery` method to convert JSON into SQL.

Demonstrates how to configure a database connection, define a JSON-based SELECT query, and generate the corresponding SQL string using `node-database-connectors`.

const connectionIdentifier = require('node-database-connectors'); // Sample database configuration const sampleConfig = { type: "database", engine: 'MyISAM', databaseType: 'mysql', database: 'test_db', host: "localhost", port: "3306", user: "root", password: process.env.DB_PASSWORD ?? '', // Use environment variables for sensitive data cacheResponse: false }; // Sample JSON query for a SELECT statement const jsonQuery = { table: "tbl_SampleMaster", alias: "SM", select: [ { field: 'pk_tableID', alias: 'pk' }, { field: 'refNumber' } ], sortby: [ { field: 'refNumber' } ], filter: { AND: [ { field: 'pk_id', operator: 'EQ', value: '1' } ] } }; try { const objConnection = connectionIdentifier.identify(sampleConfig); const generatedQuery = objConnection.prepareQuery(jsonQuery); console.log('Generated SQL Query:\n', generatedQuery); } catch (error) { console.error('Error generating query:', error.message); } // Expected Output (similar to README example): // SELECT ``.`pk_tableID` as `pk`,``.`refNumber` // FROM `tbl_SampleMaster` as SM // WHERE (``.`pk_id` = '1') // ORDER BY `refNumber` ASC;
Debug
Known issues
gotchaThe library generates SQL strings from JSON input. While it provides abstraction, proper input validation and sanitization are crucial. Directly inserting unvalidated user-supplied values into the `value` fields of `jsonQuery` could expose your application to SQL injection vulnerabilities, as the library's internal escaping mechanisms are not explicitly documented. Always sanitize or validate external input thoroughly.
fix
Ensure all user-supplied input used within `jsonQuery` (especially in `value` fields) is either strictly validated, type-checked, or explicitly escaped before being passed to the library. Consider using a dedicated input validation library or parameterized queries at the database driver level.
affects: >=1.0.0
gotchaThe library's support for specific SQL features, functions, and syntax may vary across different `databaseType` engines (e.g., 'mysql', 'postgres'). Complex or highly database-specific SQL constructs might not be fully supported, or they might generate unexpected or inefficient SQL. Always test generated queries thoroughly for your target database environment.
fix
Consult the library's documentation or source code for a definitive list of supported `databaseType` values and their respective query generation capabilities. Verify the output of `prepareQuery` in your specific database environment to ensure correctness and performance.
affects: >=1.0.0
gotchaThe library strictly expects `jsonQuery` objects to adhere to a predefined structure for each SQL operation type (SELECT, INSERT, UPDATE, DELETE). Incorrectly formatted JSON objects, missing required fields, or misspellings will lead to runtime errors during query generation.
fix
Refer to the comprehensive examples in the package's README for the correct JSON structure for each query type. Implement schema validation for `jsonQuery` objects if they are dynamically constructed from external sources to catch errors early.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: connectionIdentifier.identify is not a function
Attempting to call `identify` on an incorrectly imported or undefined `connectionIdentifier` module, often due to incorrect CommonJS `require` or ESM `import` syntax.
fix
Ensure `node-database-connectors` is correctly installed and imported as a default export using `const connectionIdentifier = require('node-database-connectors');` for CommonJS or `import connectionIdentifier from 'node-database-connectors';` for ESM.
Error: Invalid JSON query structure: 'table' is a required field.
The `jsonQuery` object provided to `prepareQuery` is missing a mandatory top-level key like `table`, which is essential for almost all SQL operations.
fix
Review your `jsonQuery` object and ensure all necessary fields, such as `table`, `select`, `insert`, `update`, or `filter`, are present and correctly structured according to the library's documentation for the intended query type.
Error: Unsupported database type: 'sqlserver'
The `databaseType` specified in your `sampleConfig` is not recognized or supported by the `node-database-connectors` library for generating SQL queries.
fix
Check the `databaseType` field in your configuration object. Use one of the officially supported types (e.g., 'mysql', 'postgres') as documented by the library.
Upgrade
Version history
1.7.20latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
node-database-connectors — npm install node-database-connectors · libregistry