{"id":43466,"library":"node-sql-2","title":"node-sql (node-sql-2)","description":"node-sql is a SQL query builder for Node.js that supports PostgreSQL, MySQL, Microsoft SQL Server, Oracle, and SQLite dialects. Current stable version is 0.80.1, maintained primarily by TokyoFarmer. It provides a fluent API to define tables and construct parameterized queries, making it composable and dialect-aware. Key differentiators include automatic parameterization, named queries, and a flexible join system. Unlike ORMs, it focuses purely on SQL generation without abstraction over database drivers. The package ships TypeScript type definitions.","status":"active","version":"0.80.1","language":"javascript","source_language":"en","source_url":"git://github.com/TokyoFarmer/node-sql-2","tags":["javascript","typescript"],"install":[{"cmd":"npm install node-sql-2","lang":"bash","label":"npm"},{"cmd":"yarn add node-sql-2","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-sql-2","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Module uses CommonJS default export. ESM import works as default.","wrong":"const sql = require('sql').default","symbol":"sql (default import)","correct":"import sql from 'sql'"},{"note":"sql.define is a method on the default export, not a named export.","wrong":"const { define } = require('sql');\nconst user = define({...})","symbol":"sql.define","correct":"import sql from 'sql';\nconst user = sql.define({ name: 'user', columns: ['id', 'name'] })"},{"note":"Query is a TypeScript type, only import as type to avoid runtime errors.","wrong":"import { Query } from 'sql'","symbol":"Query (TypeScript type)","correct":"import type { Query } from 'sql'"}],"quickstart":{"code":"const sql = require('sql');\nsql.setDialect('postgres');\n\nconst user = sql.define({\n  name: 'user',\n  columns: ['id', 'name', 'email']\n});\n\nconst query = user\n  .select(user.id, user.name)\n  .from(user)\n  .where(user.email.equals('user@example.com'))\n  .toQuery();\n\nconsole.log(query.text);\n// SELECT \"user\".\"id\", \"user\".\"name\" FROM \"user\" WHERE (\"user\".\"email\" = $1)\nconsole.log(query.values);\n// ['user@example.com']","lang":"javascript","description":"Shows basic table definition, SELECT query with parameterized WHERE clause, and retrieving the generated SQL text and values."},"warnings":[{"fix":"Use dialect-specific module or instantiate builder with dialect.","message":"sql.setDialect() is deprecated; prefer using sql.createQuery with dialect options or rely on the default postgres dialect.","severity":"deprecated","affected_versions":">=0.80.0"},{"fix":"Always reference columns using the property name if defined.","message":"All column references use property names defined in columns array, but if you use property alias, the generated SQL uses the original column name.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Check dialect-specific output and possibly use .toString() instead of .toQuery().text if adapter handles parameters.","message":"Parameterized queries use numbered placeholders ($1, $2, etc.) regardless of dialect, which may conflict with some database adapters that expect $n for PostgreSQL.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.80.1':33 '2':7 'abstract':78 'api':42 'automat':60 'awar':56 'builder':15 'compos':52 'construct':47 'current':29 'databas':80 'defin':44 'definit':87 'dialect':28,55 'dialect-awar':54 'differenti':58 'driver':81 'flexibl':66 'fluent':41 'focus':72 'generat':76 'includ':59 'javascript':88 'join':67 'key':57 'maintain':34 'make':50 'microsoft':22 'mysql':21 'name':62 'node':2,5,9 'node-sql':1,4,8 'node.js':17 'oracl':25 'orm':70 'packag':83 'parameter':48,61 'postgresql':20 'primarili':35 'provid':39 'pure':73 'queri':14,49,63 'server':24 'ship':84 'sql':3,6,10,13,23,75 'sqlite':27 'stabl':30 'support':19 'system':68 'tabl':45 'tokyofarm':37 'type':86 'typescript':85,89 'unlik':69 'version':31 'without':77","created_at":"2026-06-05T16:59:55.767877+00:00","updated_at":"2026-06-05T16:59:55.767877+00:00","problems":[{"fix":"Use 'import sql from \"sql\"' instead of named imports.","cause":"ESM import of CommonJS module without using default import.","error":"Error: require('sql') returns { default: ... } in ESM context"},{"fix":"Rename the column or access via user['select'].","cause":"Using a column name that conflicts with built-in method (e.g., 'select').","error":"TypeError: user.select 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/TokyoFarmer/node-sql-2","github":"git://github.com/TokyoFarmer/node-sql-2","docs":null,"changelog":null,"pypi":null,"npm":"node-sql-2","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}}