{"id":43910,"library":"sql-js-builder","title":"sql-js-builder","description":"A lightweight, driver-agnostic SQL WHERE clause builder that uses plain JavaScript data structures and the builder pattern. Version 0.0.18 ships TypeScript types and is released on npm. Unlike many SQL builders, this library does not depend on any specific database driver or ORM, outputting raw SQL fragments with `?` placeholders. It is designed to simplify constructing parameterized WHERE clauses without string concatenation, with a focus on maintainability and minimal external dependencies. The library currently supports basic comparison operators (eq, neq, gt, gte, lt, lte) and logical grouping, but does not support indexed placeholders, joins, or subqueries. Its release cadence is infrequent, with the last update in 2024.","status":"active","version":"0.0.18","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","typescript"],"install":[{"cmd":"npm install sql-js-builder","lang":"bash","label":"npm"},{"cmd":"yarn add sql-js-builder","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-js-builder","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Use named import, not default. The library has no default export.","wrong":"import where from 'sql-js-builder'","symbol":"where","correct":"import { where } from 'sql-js-builder'"},{"note":"Operator strings must be lowercase (eq, neq, gt, gte, lt, lte). Double quotes around identifiers are fine but not mandatory.","wrong":"where().and(\"col\", \"eq\", val)","symbol":"and","correct":"where().and('col', 'eq', val)"},{"note":"Destructure the result object to get sql and values arrays. build() does not accept arguments.","wrong":"const result = where().build(); result.sql; result.values","symbol":"build","correct":"const { sql, values } = where().build()"}],"quickstart":{"code":"import { where } from 'sql-js-builder';\n\nconst { sql, values } = where()\n  .and('age', 'gte', 18)\n  .and('country', 'eq', 'Brazil')\n  .build();\n\n// Use the fragment with your own query\nconst query = `SELECT * FROM users WHERE ${sql}`;\nconsole.log(query); // SELECT * FROM users WHERE 1 = 1 AND \"age\" >= ? AND \"country\" = ?\nconsole.log(values); // [18, 'Brazil']\n\n// For databases using indexed placeholders (e.g. PostgreSQL $1, $2):\nconst reindexedSql = sql.replace(/\\?/g, (match, offset) => {\n  let idx = 1;\n  // simple replacement: assumes ? are not in strings\n  return `$${idx++}`;\n});","lang":"typescript","description":"Shows how to build a WHERE clause with multiple conditions, destructure the SQL and values, and adapt for databases with different placeholder styles."},"warnings":[{"fix":"Write a helper function to replace `?` with indexed placeholders based on the order of values.","message":"Placeholders are always `?` which may not be compatible with all databases (e.g. PostgreSQL requires $1, $2). User must manually re-index placeholders.","severity":"gotcha","affected_versions":"all"},{"fix":"Avoid dynamic column names; if necessary, sanitize or quote them manually using backticks or double quotes.","message":"Column names are not escaped or quoted automatically. If column names contain special characters or are reserved words, SQL injection is possible through column names.","severity":"gotcha","affected_versions":"all"},{"fix":"Use raw SQL fragments for complex conditions or consider an alternative library with broader operator support.","message":"Only supports equality and comparison operators (eq, neq, gt, gte, lt, lte). No IN, LIKE, BETWEEN, IS NULL, or other SQL operators.","severity":"gotcha","affected_versions":"all"},{"fix":"Construct your own WHERE fragments manually for advanced logic, or use a more comprehensive SQL builder.","message":"No support for OR clauses, nested grouping, or complex boolean logic. The builder only chains AND conditions.","severity":"gotcha","affected_versions":"all"},{"fix":"Monitor the repository for updates or consider migrating to a maintained alternative.","message":"The package has not been updated since 2024; future compatibility with newer Node.js or driver versions is uncertain.","severity":"deprecated","affected_versions":"all"}],"env_vars":null,"search_vec":"'0.0.18':25 '2024':112 'agnost':9 'basic':81 'builder':4,13,22,37 'cadenc':104 'claus':12,64 'comparison':82 'concaten':67 'construct':61 'current':79 'data':18 'databas':46 'depend':42,76 'design':58 'driver':8,47 'driver-agnost':7 'eq':84 'extern':75 'focus':70 'fragment':53 'group':92 'gt':86 'gte':87 'index':97 'infrequ':106 'javascript':17,113 'join':99 'js':3 'last':109 'librari':39,78 'lightweight':6 'logic':91 'lt':88 'lte':89 'maintain':72 'mani':35 'minim':74 'neq':85 'npm':33 'oper':83 'orm':49 'output':50 'parameter':62 'pattern':23 'placehold':55,98 'plain':16 'raw':51 'releas':31,103 'ship':26 'simplifi':60 'specif':45 'sql':2,10,36,52 'sql-js-builder':1 'string':66 'structur':19 'subqueri':101 'support':80,96 'type':28 'typescript':27,114 'unlik':34 'updat':110 'use':15 'version':24 'without':65","created_at":"2026-06-05T17:02:03.762122+00:00","updated_at":"2026-06-05T17:02:03.762122+00:00","problems":[{"fix":"Change 'import where from \"sql-js-builder\"' to 'import { where } from \"sql-js-builder\"'.","cause":"Using default import instead of named import.","error":"TypeError: (0 , sql_js_builder_1.where) is not a function"},{"fix":"Quote column names manually: .and('\"user status\"', 'eq', 'active')","cause":"Trying to use a column name that contains spaces or special characters without quoting.","error":"The column name \"status\" is not recognized."},{"fix":"Use raw SQL: `{ sql: \\`\"col\" IN (${values.map(() => '?').join(',')})\\`, values: [...] }`","cause":"SQL JS Builder only supports eq, neq, gt, gte, lt, lte.","error":"Operator \"in\" is not supported."}],"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":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"sql-js-builder","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}}