{"library":"node-database-connectors","title":"node-database-connectors: JSON to SQL Query Builder","description":"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.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install node-database-connectors"],"cli":null},"imports":["import connectionIdentifier from 'node-database-connectors';","const connectionIdentifier = require('node-database-connectors');","const objConnection = connectionIdentifier.identify(sampleConfig);\nconst query = objConnection.prepareQuery(jsonQuery);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const connectionIdentifier = require('node-database-connectors');\n\n// Sample database configuration\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 variables for sensitive data\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: [\n    { field: 'refNumber' }\n  ],\n  filter: {\n    AND: [\n      { field: 'pk_id', operator: 'EQ', value: '1' }\n    ]\n  }\n};\n\ntry {\n  const objConnection = connectionIdentifier.identify(sampleConfig);\n  const generatedQuery = objConnection.prepareQuery(jsonQuery);\n  console.log('Generated SQL Query:\\n', generatedQuery);\n} catch (error) {\n  console.error('Error generating query:', error.message);\n}\n\n// Expected Output (similar to README example):\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 configure a database connection, define a JSON-based SELECT query, and generate the corresponding SQL string using `node-database-connectors`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}