{"id":43878,"library":"sql-builder.js","title":"sql-builder.js","description":"sql-builder.js v2.1.0 is a lightweight, zero-dependency SQL query builder for JavaScript and TypeScript with built-in SQL injection protection via parameterized queries and identifier validation. It supports ESM and CJS, provides a fluent chainable API for SELECT, INSERT, UPDATE, DELETE, and UPSERT, and includes advanced features like raw expressions, joins, and pagination. Compared to alternatives like knex.js, it is significantly smaller and simpler, with no external dependencies, but lacks database dialect-specific features and migration tooling. The package is released under the Anti 996 license, requires Node >=14, and follows an active release cadence.","status":"active","version":"2.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/axetroy/sql-builder.js","tags":["javascript","sql","sql-builder"],"install":[{"cmd":"npm install sql-builder.js","lang":"bash","label":"npm"},{"cmd":"yarn add sql-builder.js","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-builder.js","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export only. CommonJS: const { SQLBuilder } = require('sql-builder.js').","wrong":"import SQLBuilder from 'sql-builder.js'","symbol":"SQLBuilder","correct":"import { SQLBuilder } from 'sql-builder.js'"},{"note":"Named export for embedding raw SQL expressions. CommonJS: const { raw } = require('sql-builder.js').","wrong":"const raw = require('sql-builder.js').raw","symbol":"raw","correct":"import { raw } from 'sql-builder.js'"},{"note":"TypeScript type export, not a runtime value. Use 'import type' to avoid runtime errors.","wrong":"import { SQLBuilderOptions } from 'sql-builder.js'","symbol":"SQLBuilderOptions","correct":"import type { SQLBuilderOptions } from 'sql-builder.js'"}],"quickstart":{"code":"import { SQLBuilder } from 'sql-builder.js';\n\nconst sqlBuilder = new SQLBuilder();\n\n// Build a SELECT query\nconst result = sqlBuilder\n  .select('*')\n  .from('users')\n  .where('age', '>', 18)\n  .build();\n\nconsole.log(result.sql);       // SELECT * FROM `users` WHERE `age` > ?\nconsole.log(result.params);    // [18]\nconsole.log(result.toString()); // SELECT * FROM `users` WHERE `age` > 18\n\n// INSERT example\nconst insertResult = sqlBuilder\n  .insert('users', { name: 'Alice', age: 25 })\n  .build();\n\nconsole.log(insertResult.sql);     // INSERT INTO `users` (`name`, `age`) VALUES (?, ?)\nconsole.log(insertResult.params);  // ['Alice', 25]","lang":"typescript","description":"Create SQLBuilder instance, build a SELECT query with parameterized where clause, and demonstrate INSERT query."},"warnings":[{"fix":"Only use `raw()` with trusted inputs or heavily sanitized values. Prefer parameterized queries over raw expressions whenever possible.","message":"The `raw()` function bypasses parameterization and can introduce SQL injection if user input is concatenated unsafely.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use explicit aliases with AS keyword: 'users AS u'. For column-qualified names, use dot notation only when the alias is expected (e.g., 'u.id').","message":"Table and column names are backtick-quoted by default. If you use dots or aliases (e.g., 'users u'), they may not be quoted correctly, leading to syntax errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Create a new SQLBuilder instance for each query, or clone the builder if supported (check docs).","message":"The `build()` method returns a new object each time, but the builder instance is mutated. Reusing the same builder for multiple queries can produce unintended results.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `raw('1')` for literal numbers, but be aware of injection risks.","message":"String values are always parameterized, but numeric values are also parameterized. If you need to embed a numeric literal directly, use `raw()`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use `raw()` from the package for raw expressions, not plain strings.","message":"The `raw()` function usage with `set()` in UPDATE may change in future versions. Currently, you can pass a raw object or a string to set().","severity":"deprecated","affected_versions":">=2.0.0"}],"env_vars":null,"search_vec":"'14':93 '996':89 'activ':97 'advanc':49 'altern':59 'anti':88 'api':39 'builder':12,104 'built':19 'built-in':18 'cadenc':99 'chainabl':38 'cjs':34 'compar':57 'databas':74 'delet':44 'depend':9,71 'dialect':76 'dialect-specif':75 'esm':32 'express':53 'extern':70 'featur':50,78 'fluent':37 'follow':95 'identifi':28 'includ':48 'inject':22 'insert':42 'javascript':14,100 'join':54 'knex.js':61 'lack':73 'licens':90 'lightweight':6 'like':51,60 'migrat':80 'node':92 'packag':83 'pagin':56 'parameter':25 'protect':23 'provid':35 'queri':11,26 'raw':52 'releas':85,98 'requir':91 'select':41 'signific':64 'simpler':67 'smaller':65 'specif':77 'sql':10,21,101,103 'sql-builder':102 'sql-builder.js':1,2 'support':31 'tool':81 'typescript':16 'updat':43 'upsert':46 'v2.1.0':3 'valid':29 'via':24 'zero':8 'zero-depend':7","created_at":"2026-06-05T17:01:54.564909+00:00","updated_at":"2026-06-05T17:01:54.564909+00:00","problems":[{"fix":"Use: import { SQLBuilder } from 'sql-builder.js'","cause":"Using default import instead of named import.","error":"TypeError: SQLBuilder is not a constructor"},{"fix":"Run: npm install sql-builder.js --save","cause":"Package not installed or import path is wrong.","error":"Cannot find module 'sql-builder.js'"},{"fix":"Use CommonJS: const { SQLBuilder } = require('sql-builder.js')","cause":"Using ESM syntax in a CommonJS environment without transpilation.","error":"SyntaxError: Unexpected token 'export'"},{"fix":"Use the `raw()` function to bypass validation or adjust the column name to match allowed pattern.","cause":"Identifier validation is enabled by default; column name contains disallowed characters.","error":"Column 'foo' is not allowed"}],"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/axetroy/sql-builder.js#readme","github":"https://github.com/axetroy/sql-builder.js","docs":null,"changelog":null,"pypi":null,"npm":"sql-builder.js","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}}