{"id":17197,"library":"database-connectors","title":"Database Query Generator","description":"The `database-connectors` package is a Node.js library designed to convert structured JSON objects into database-specific SQL queries. It provides functionality to generate common SQL statements such as SELECT, INSERT, UPDATE, and DELETE, accommodating complex structures like table joins and conditional filtering. The current stable version, 1.0.3, was last published in 2015, indicating that the library is no longer actively maintained. Its core differentiation lies in abstracting SQL syntax behind a programmatic JSON interface, allowing developers to define query logic without directly writing raw SQL, thereby aiming to simplify data access layers and standardize query construction for MySQL-like databases. This focus on query preparation, rather than direct database execution, implies it is a utility for building queries to be passed to a separate database client.","status":"abandoned","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/Jignesh-cephei/database-connector","tags":["javascript"],"install":[{"cmd":"npm install database-connectors","lang":"bash","label":"npm"},{"cmd":"yarn add database-connectors","lang":"bash","label":"yarn"},{"cmd":"pnpm add database-connectors","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS only. The README incorrectly references `require('node-database-connectors')` while the npm package is `database-connectors`.","wrong":"import connectionIdentifier from 'database-connectors';","symbol":"default export (object with identify method)","correct":"const connectionIdentifier = require('database-connectors');"},{"note":"The `identify` method is part of the default exported object, not a named export. It takes a configuration object to determine the database type.","wrong":"const { identify } = require('database-connectors');","symbol":"identify","correct":"const connectionIdentifier = require('database-connectors');\nconst objConnection = connectionIdentifier.identify(sampleConfig);"},{"note":"The `prepareQuery` method is invoked on the object returned by `identify`, taking a JSON object representing the desired SQL query.","symbol":"prepareQuery","correct":"const connectionIdentifier = require('database-connectors');\nconst objConnection = connectionIdentifier.identify(sampleConfig);\nconst query = objConnection.prepareQuery(jsonQuery);"}],"quickstart":{"code":"const connectionIdentifier = require('database-connectors');\n\n// Sample database configuration (MySQL assumed based on README)\nconst sampleConfig = {\n  type: \"database\",\n  engine: 'MyISAM',\n  databaseType: 'mysql',\n  database: 'test_db',\n  host: \"localhost\",\n  port: \"3306\",\n  user: \"root\",\n  password: process.env.DB_PASSWORD ?? '', // Use environment variable for password\n  cacheResponse: false\n};\n\n// Sample JSON query for a SELECT statement\nconst jsonQuery = {\n  table: \"tbl_SampleMaster\",\n  alias: \"SM\",\n  select: [\n    { field: 'pk_tableID', alias: 'pk' },\n    { field: 'refNumber' }\n  ],\n  sortby: [{ field: 'refNumber' }],\n  filter: {\n    AND: [{ field: 'pk_id', operator: 'EQ', value: '1' }]\n  }\n};\n\ntry {\n  // Identify the connection type and get the connector object\n  const objConnection = connectionIdentifier.identify(sampleConfig);\n  \n  // Prepare the SQL query from the JSON object\n  const query = objConnection.prepareQuery(jsonQuery);\n\n  console.log('Generated SQL Query:');\n  console.log(query);\n} catch (error) {\n  console.error('Error generating query:', error.message);\n}\n\n// Example output for the above:\n// SELECT ``.`pk_tableID` as `pk`,``.`refNumber`\n// FROM `tbl_SampleMaster` as SM\n// WHERE (``.`pk_id` = '1')\n// ORDER BY `refNumber` ASC;","lang":"javascript","description":"Demonstrates how to initialize a database connector configuration and generate a SQL SELECT query from a JSON object using the library's `identify` and `prepareQuery` methods."},"warnings":[{"fix":"Consider migrating to a actively maintained ORM or query builder library for modern Node.js environments and better security posture.","message":"The package has not been updated since 2015 (v1.0.3), meaning it lacks support for modern JavaScript features (ESM) and may not be compatible with newer Node.js versions or database systems/standards. Security vulnerabilities are unlikely to be patched.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Always use `require('database-connectors')` to import the package.","message":"The README examples use `require('node-database-connectors')`, but the actual npm package is `database-connectors`. Using the name `node-database-connectors` will result in a 'Cannot find module' error.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If integrating into an ESM project, you would need to use dynamic `import()` or configure your build system to handle CJS modules. However, given the package's age, migration is strongly advised.","message":"This library is CommonJS-only (`require`). It does not support ES Modules (`import`), which is the standard module system for modern JavaScript development in Node.js and browsers.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Thoroughly test generated queries against your target database version. Manual inspection and potential adjustments of the JSON query structure might be necessary for complex or performance-critical queries.","message":"The generated SQL syntax might be outdated or not fully compatible with advanced features or specific dialects of modern database versions beyond basic MySQL. For example, `engine: 'MyISAM'` is an outdated MySQL storage engine, and the SQL generated may not optimize for newer features.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Change your file to use CommonJS (e.g., ensure it's a `.js` file without `\"type\": \"module\"`) or use dynamic import: `import('database-connectors').then(module => { /* use module.default */ })`.","cause":"Attempting to use `require()` in an ES Module (ESM) context (e.g., in a file with `\"type\": \"module\"` in package.json or a `.mjs` file).","error":"ReferenceError: require is not defined"},{"fix":"Ensure you are using `const connectionIdentifier = require('database-connectors');` and not a named import. Verify the package is correctly installed.","cause":"This usually happens if the package was imported incorrectly, or if the `database-connectors` package itself doesn't export an `identify` method directly (though the README suggests it does). Could also happen if `require()` fails silently or returns an empty object.","error":"TypeError: connectionIdentifier.identify is not a function"},{"fix":"Update your `require()` statement to `const connectionIdentifier = require('database-connectors');`","cause":"The `require()` statement uses the module name `node-database-connectors` as shown in the README, but the actual npm package name is `database-connectors`.","error":"Error: Cannot find module 'node-database-connectors'"}],"ecosystem":"npm","meta_description":null}