{"id":43977,"library":"sql","title":"node-sql","description":"SQL query string builder for Node.js supporting PostgreSQL, MySQL, MSSQL, Oracle, and SQLite. Current version 0.78.0 (as of 2019). Queries are parameterized by default to prevent SQL injection. Tables are defined in JavaScript, and query building is composable and chainable. Differentiates from other query builders by its simple API and support for multiple dialects with a single unified interface. Last stable release was over 5 years ago; the project appears to be in maintenance mode with no recent commits.","status":"maintenance","version":"0.78.0","language":"javascript","source_language":"en","source_url":"git://github.com/brianc/node-sql","tags":["javascript","typescript"],"install":[{"cmd":"npm install sql","lang":"bash","label":"npm"},{"cmd":"yarn add sql","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Common companion package for auto-generating table definitions","package":"sql-extra","optional":true}],"imports":[{"note":"Package ships TypeScript types but CommonJS usage is still common; ESM works for Node >=16 with type: module or .mjs","wrong":"var sql = require('sql');","symbol":"sql","correct":"import sql from 'sql'"},{"note":"`sql.define` is static method on default import.","wrong":"const table = require('sql').define({...})","symbol":"sql.define","correct":"import sql from 'sql'; const table = sql.define({ name: 'users', columns: ['id', 'name'] })"},{"note":"TypeScript type for defined table. Not commonly used in JS, toQuery() returns object.","wrong":"import { Table as t } from 'sql'","symbol":"Table","correct":"import { Table } from 'sql'"}],"quickstart":{"code":"import sql from 'sql';\n\nsql.setDialect('postgres');\n\nconst user = sql.define({\n  name: 'user',\n  columns: ['id', 'name', 'email', 'lastLogin']\n});\n\nconst query = user\n  .select(user.id, user.name)\n  .from(user)\n  .where(user.name.equals('John').and(user.id.equals(1)))\n  .or(user.email.equals('john@example.com'))\n  .order(user.lastLogin.descending)\n  .toQuery();\n\nconsole.log(query.text);\n// SELECT \"user\".\"id\", \"user\".\"name\" FROM \"user\" WHERE ((\"user\".\"name\" = $1) AND (\"user\".\"id\" = $2)) OR (\"user\".\"email\" = $3) ORDER BY \"user\".\"lastLogin\" DESC\nconsole.log(query.values); // ['John', 1, 'john@example.com']","lang":"typescript","description":"Defines a table, builds a SELECT query with WHERE, OR, ORDER BY, and outputs parameterized text and values."},"warnings":[{"fix":"Call sql.setDialect('mysql') at the start of your app if you use MySQL.","message":"Version 0.72.0 changed the default dialect from MySQL to PostgreSQL. Existing queries may break if dialect not set explicitly.","severity":"breaking","affected_versions":"<0.72.0"},{"fix":"Replace `table.toKeyword()` with `toQuery().text` and `table.toParameter(column)` with parameterized `toQuery().values`.","message":"The `toKeyword()` and `toParameter()` functions are deprecated; use `toQuery()` instead.","severity":"deprecated","affected_versions":">=0.60.0"},{"fix":"Ensure column names in `columns` array or object match exactly with property accessed.","message":"Column property names are case-sensitive and must match exactly. Using wrong case will silently default to the property value.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Always specify `.on(condition)` after `.join()` or `.leftJoin()`.","message":"Joins without explicit ON clause may produce unexpected SQL. The package does not warn if ON is omitted.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Update table definitions to use `columns` array instead of `properties`.","message":"In version 0.68.0, `sql.define` changed from accepting an object with `properties` to an object with `columns`. Old property definitions may break.","severity":"breaking","affected_versions":"<0.68.0"},{"fix":"Use the `text` property directly; append semicolon if required by your database driver.","message":"The `toQuery()` method returns an object with `text` and `values` properties, but `text` is not always a valid SQL string (e.g., missing semicolon).","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.78.0':19 '2019':22 '5':68 'ago':70 'api':52 'appear':73 'build':39 'builder':7,48 'chainabl':43 'commit':82 'compos':41 'current':17 'default':27 'defin':34 'dialect':57 'differenti':44 'inject':31 'interfac':62 'javascript':36,83 'last':63 'mainten':77 'mode':78 'mssql':13 'multipl':56 'mysql':12 'node':2 'node-sql':1 'node.js':9 'oracl':14 'parameter':25 'postgresql':11 'prevent':29 'project':72 'queri':5,23,38,47 'recent':81 'releas':65 'simpl':51 'singl':60 'sql':3,4,30 'sqlite':16 'stabl':64 'string':6 'support':10,54 'tabl':32 'typescript':84 'unifi':61 'version':18 'year':69","created_at":"2026-06-05T17:02:23.617877+00:00","updated_at":"2026-06-05T17:02:23.617877+00:00","problems":[{"fix":"Ensure that you have defined the table with sql.define() and that the query chain is complete (e.g., .from(table) called).","cause":"Calling toQuery() on a query object that was not properly built (e.g., missing table definition).","error":"Cannot read property 'text' of undefined"},{"fix":"Verify that `const user = sql.define({...})` is called correctly and that you are using ES module import or CommonJS require correctly.","cause":"`sql.define` returns a Table object, but attempting to access `user.select` on a wrong import or typo.","error":"TypeError: user.select is not a function"},{"fix":"Add `import sql from 'sql'` (ESM) or `const sql = require('sql')` (CommonJS) at the top of your file.","cause":"Missing require or import statement for the 'sql' package.","error":"ReferenceError: sql is not defined"},{"fix":"Use one of: 'postgres', 'mysql', 'mssql', 'sqlite' or install a dialect plugin (if available).","cause":"The 'oracle' dialect is not bundled by default; requires separate plugin.","error":"Dialect not supported: oracle"}],"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/brianc/node-sql","github":"git://github.com/brianc/node-sql","docs":null,"changelog":null,"pypi":null,"npm":"sql","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}}