{"id":43936,"library":"sql-query-generator","title":"sql-query-generator","description":"A schemaless SQL query builder for Node.js (v1.4.2) that generates parameterized SQL statements for PostgreSQL (default), MySQL, and MSSQL dialects. Unlike ORMs or schema-based builders, it works without any model definitions, making it ideal for dynamic queries. It supports SELECT, INSERT, UPDATE, DELETE operations with WHERE, ORDER BY, LIMIT/OFFSET, and JOINs. Includes TypeScript definitions. Release cadence is low; last release was March 2025.","status":"active","version":"1.4.2","language":"javascript","source_language":"en","source_url":"https://github.com/vedard/sql-query-generator","tags":["javascript","sql","query","generator","builder","schemaless","generation","insert","update","typescript"],"install":[{"cmd":"npm install sql-query-generator","lang":"bash","label":"npm"},{"cmd":"yarn add sql-query-generator","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-query-generator","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import style; CJS require also works with default export.","wrong":"const sql = require('sql-query-generator')","symbol":"default","correct":"import sql from 'sql-query-generator'"},{"note":"Statement is not exported; it's an internal class returned by methods.","wrong":"import { Statement } from 'sql-query-generator'","symbol":"Statement","correct":"import sql from 'sql-query-generator'"},{"note":"Types are bundled; no separate import needed. Use `import type { Statement } from 'sql-query-generator'` if needed.","wrong":"import { SqlQueryGenerator } from 'sql-query-generator'","symbol":"TypeScript types","correct":"import sql from 'sql-query-generator'"}],"quickstart":{"code":"import sql from 'sql-query-generator';\n\nsql.use('postgres'); // or 'mysql', 'mssql'\n\n// Insert\nconst insertStmt = sql.insert('users', { name: 'John', email: 'john@example.com' });\nconsole.log(insertStmt.text);\n// INSERT INTO users (name, email) VALUES ($1, $2)\nconsole.log(insertStmt.values);\n// ['John', 'john@example.com']\n\n// Select with where\nconst selectStmt = sql.select('users', ['id', 'name']).where({ email: 'john@example.com' });\nconsole.log(selectStmt.text);\n// SELECT id, name FROM users WHERE email = $1\n\n// Update\nconst updateStmt = sql.update('users', { name: 'Jane' }).where({ id: 1 });\nconsole.log(updateStmt.text);\n// UPDATE users SET name = $1 WHERE id = $2\n\n// Delete\nconst deleteStmt = sql.deletes('users').where({ id: 1 });\nconsole.log(deleteStmt.text);\n// DELETE FROM users WHERE id = $1","lang":"typescript","description":"Demonstrates basic CRUD operations (INSERT, SELECT, UPDATE, DELETE) with parameterized queries and dialect selection."},"warnings":[{"fix":"Use sql.deletes('table') instead of sql.delete('table').","message":"The delete method is named `deletes`, not `delete`.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Call sql.use('mysql') or sql.use('mssql') after import.","message":"The `use` method must be called before any query methods to set the dialect; default is postgres.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"The library does not convert to ? or @p1; you must handle parameterization externally if needed.","message":"All parameter placeholders use $1, $2, etc., even for MySQL and MSSQL dialects.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Pass columns as array of strings or comma-separated string. Do not include functions like COUNT(*).","message":"The `select` method's second argument can be a string, array, or '*' but does not support raw SQL expressions.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"sql.where({a:1, b:2}, '=', 'OR') produces (a = $1 OR b = $2).","message":"The `where` method's logical operator defaults to 'AND'; use the third argument to set 'OR'.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'2025':69 'base':30 'builder':9,31,74 'cadenc':62 'default':20 'definit':37,60 'delet':49 'dialect':24 'dynam':42 'generat':4,14,73,76 'ideal':40 'includ':58 'insert':47,77 'javascript':70 'join':57 'last':65 'limit/offset':55 'low':64 'make':38 'march':68 'model':36 'mssql':23 'mysql':21 'node.js':11 'oper':50 'order':53 'orm':26 'parameter':15 'postgresql':19 'queri':3,8,43,72 'releas':61,66 'schema':29 'schema-bas':28 'schemaless':6,75 'select':46 'sql':2,7,16,71 'sql-query-gener':1 'statement':17 'support':45 'typescript':59,79 'unlik':25 'updat':48,78 'v1.4.2':12 'without':34 'work':33","created_at":"2026-06-05T17:02:11.250659+00:00","updated_at":"2026-06-05T17:02:11.250659+00:00","problems":[{"fix":"Replace sql.delete('table') with sql.deletes('table').","cause":"The delete method is named `deletes` to avoid conflict with JavaScript's `delete` keyword.","error":"sql.delete is not a function"},{"fix":"Run npm install sql-query-generator in your project root.","cause":"Package not installed or missing from dependencies.","error":"Cannot find module 'sql-query-generator'"},{"fix":"Ensure all required arguments are provided. Example: sql.select('table', '*').text","cause":"Calling .text on a statement that was not generated correctly (e.g., missing table name in select).","error":"Cannot read properties of null (reading 'text')"},{"fix":"Upgrade to version 1.x by running npm install sql-query-generator@latest.","cause":"Using a version that does not support the `use` method (possibly very old).","error":"TypeError: sql.use is not a function"}],"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/vedard/sql-query-generator","github":"https://github.com/vedard/sql-query-generator","docs":null,"changelog":null,"pypi":null,"npm":"sql-query-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}}