{"id":43912,"library":"sql-json-generator","title":"sql-json-generator","description":"sql-json-generator (v0.15.1) is a Node.js module that generates SQL queries (SELECT, INSERT, UPDATE, DELETE) from JSON objects, loosely based on MongoDB query syntax. It supports MySQL features like backtick escaping, aggregate functions, joins, subqueries via $raw, and SqlCalcFoundRows. The library is designed to simplify building reusable JSON query definitions for REST APIs with MySQL backends. It is not ESM-native and relies on CommonJS. Updates are infrequent; the last release was in 2021. Compared to alternatives like knex.js or sequelize, it is more lightweight but lacks ORM features and broader database support.","status":"maintenance","version":"0.15.1","language":"javascript","source_language":"en","source_url":"https://github.com/manu-de-verdun/sql-json-generator","tags":["javascript","SQL","JSON","NODE"],"install":[{"cmd":"npm install sql-json-generator","lang":"bash","label":"npm"},{"cmd":"yarn add sql-json-generator","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-json-generator","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Optional peer dependency for MySQL-specific escaping and features like SqlCalcFoundRows.","package":"mysql","optional":true}],"imports":[{"note":"Package is CommonJS only; ES import may fail or require bundler handling.","wrong":"import SQLGenerator from 'sql-json-generator';","symbol":"default","correct":"const SQLGenerator = require('sql-json-generator'); const sqlGenerator = new SQLGenerator();"},{"note":"Constructor name is SQLGenerator, case-sensitive.","wrong":"const sqlGenerator = new SqlJsonGenerator();","symbol":"constructor","correct":"const sqlGenerator = new SQLGenerator();"},{"note":"Method names are lowercase: select, insert, update, delete.","wrong":"new SQLGenerator().SELECT({...})","symbol":"select","correct":"sqlGenerator.select({...})"}],"quickstart":{"code":"const SQLGenerator = require('sql-json-generator');\nconst sqlGenerator = new SQLGenerator();\n\nconst queryData = {\n  $from: 'users',\n  $fields: ['id', 'name', 'email'],\n  $where: [{ status: 'active' }],\n  $order: { name: 1 },\n  $limit: 10\n};\n\nconst sql = sqlGenerator.select(queryData);\nconsole.log(sql);\n// SELECT `id`, `name`, `email` FROM `users` WHERE `users`.`status` = 'active' ORDER BY `users`.`name` ASC LIMIT 10","lang":"javascript","description":"Shows basic SELECT query generation with fields, WHERE condition, ordering, and limit."},"warnings":[{"fix":"Use $from object with sqlCalcFoundRows property.","message":"$sqlCalcFoundRows is legacy syntax; use $from: { table: 'table', sqlCalcFoundRows: true } instead.","severity":"deprecated","affected_versions":"<=0.14.0"},{"fix":"Use explicit $field objects with $as for aliasing.","message":"The library does not escape column names for aliases; providing an alias like 'table.column' may break.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use $and/$or explicit arrays to control logic grouping.","message":"$where clauses are always wrapped in parentheses; multiple conditions may produce unexpected grouping.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use Node.js 8 or later.","message":"Removed support for Node.js <8 in v0.12.0.","severity":"breaking","affected_versions":">=0.12.0"}],"env_vars":null,"search_vec":"'2021':81 'aggreg':38 'altern':84 'api':59 'backend':62 'backtick':36 'base':26 'broader':98 'build':52 'commonj':72 'compar':82 'databas':99 'definit':56 'delet':21 'design':49 'escap':37 'esm':67 'esm-nat':66 'featur':34,96 'function':39 'generat':4,8,15 'infrequ':75 'insert':19 'javascript':101 'join':40 'json':3,7,23,54,103 'knex.js':86 'lack':94 'last':77 'librari':47 'lightweight':92 'like':35,85 'loos':25 'modul':13 'mongodb':28 'mysql':33,61 'nativ':68 'node':104 'node.js':12 'object':24 'orm':95 'queri':17,29,55 'raw':43 'releas':78 'reli':70 'rest':58 'reusabl':53 'select':18 'sequel':88 'simplifi':51 'sql':2,6,16,102 'sql-json-gener':1,5 'sqlcalcfoundrow':45 'subqueri':41 'support':32,100 'syntax':30 'updat':20,73 'v0.15.1':9 'via':42","created_at":"2026-06-05T17:02:04.444344+00:00","updated_at":"2026-06-05T17:02:04.444344+00:00","problems":[{"fix":"Use CommonJS require: const SQLGenerator = require('sql-json-generator');","cause":"Attempting to import using ES module syntax without proper transpilation.","error":"TypeError: SQLGenerator is not a constructor"},{"fix":"Instantiate first: const sqlGenerator = new SQLGenerator();","cause":"Calling select() before instantiating with 'new'.","error":"sqlGenerator.select is not a function"},{"fix":"Ensure $from is a string or object within queryData.","cause":"Passing a raw object instead of a defined JSON structure.","error":"ReferenceError: $from is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/manu-de-verdun/sql-json-generator#readme","github":"https://github.com/manu-de-verdun/sql-json-generator","docs":null,"changelog":null,"pypi":null,"npm":"sql-json-generator","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}