{"id":42696,"library":"embrace-sql","title":"Embrace SQL","description":"Embrace SQL is a JavaScript library for composing SQL queries programmatically using a chainable, fluent API. Current stable version is 2.0.1. It focuses on composing dynamic SQL with a simple, intuitive API that leverages tagged template literals. Key differentiators include zero dependencies, support for PostgreSQL style queries, and a lightweight footprint compared to full ORMs. The library is released as a single package with CJS and ESM exports. It is ideal for projects that need to build SQL queries without the overhead of an ORM.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/jzimmek/embrace-sql","tags":["javascript","sql","compose","composition","db","database","pg","postgresql"],"install":[{"cmd":"npm install embrace-sql","lang":"bash","label":"npm"},{"cmd":"yarn add embrace-sql","lang":"bash","label":"yarn"},{"cmd":"pnpm add embrace-sql","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export is the main query builder. Named export does not exist.","wrong":"import { sql } from 'embrace-sql'","symbol":"default","correct":"import sql from 'embrace-sql'"},{"note":"CJS require works for default export.","symbol":"sql","correct":"const sql = require('embrace-sql')"},{"note":"TypeScript types are available; QueryBuilder is an internal type.","symbol":"types","correct":"import type { QueryBuilder } from 'embrace-sql'"}],"quickstart":{"code":"import sql from 'embrace-sql';\n\nconst query = sql`SELECT * FROM users WHERE age > ${21}`;\nconsole.log(query.text); // 'SELECT * FROM users WHERE age > $1'\nconsole.log(query.values); // [21]\n\n// Chainable API\nconst q = sql`SELECT * FROM users`\n  .where`age > ${18}`\n  .orderBy`name`\n  .limit(10);\n\nconsole.log(q.compile());\n// { text: 'SELECT * FROM users WHERE age > $1 ORDER BY name LIMIT $2', values: [18, 10] }","lang":"typescript","description":"Demonstrates basic usage: creating parameterized queries and chaining methods."},"warnings":[{"fix":"Always use backticks with the tag: sql`...${value}...`","message":"Tagged template literals must be used correctly; values are automatically parameterized.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update to use tagged template syntax: `.where\\`condition\\``","message":"Version 2.0.0 changed the chainable API: previously `.where(sql\\`...\\`)` was used, now it's `.where\\`...\\`.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"Use `.where\\`cond1 AND cond2\\`` instead.","message":"The `.and` and `.or` methods were deprecated in 2.0.1 in favor of combining conditions with `.where`.","severity":"deprecated","affected_versions":">=2.0.1"},{"fix":"Use `query.text` and `query.values` when passing to a database driver.","message":"The `compile()` method returns an object with `text` and `values`; not a string.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade Node.js to >=14.","message":"Version 2.0 removed support for Node.js < 14.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use `sql.raw` for identifiers: sql`SELECT ${sql.raw('col')} FROM table`","message":"Identifier interpolation (e.g., column names) must be done differently; direct variable interpolation is treated as values.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Never pass user-generated strings to `sql.raw` without validation.","message":"Using `sql.raw` with unsanitized user input can lead to SQL injection.","severity":"security","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2.0.1':23 'api':18,34 'build':79 'chainabl':16 'cjs':67 'compar':54 'compos':10,27,90 'composit':91 'current':19 'databas':93 'db':92 'depend':44 'differenti':41 'dynam':28 'embrac':1,3 'esm':69 'export':70 'fluent':17 'focus':25 'footprint':53 'full':56 'ideal':73 'includ':42 'intuit':33 'javascript':7,88 'key':40 'leverag':36 'librari':8,59 'lightweight':52 'liter':39 'need':77 'orm':57,87 'overhead':84 'packag':65 'pg':94 'postgresql':47,95 'programmat':13 'project':75 'queri':12,49,81 'releas':61 'simpl':32 'singl':64 'sql':2,4,11,29,80,89 'stabl':20 'style':48 'support':45 'tag':37 'templat':38 'use':14 'version':21 'without':82 'zero':43","created_at":"2026-06-05T16:56:14.025825+00:00","updated_at":"2026-06-05T16:56:14.025825+00:00","problems":[{"fix":"Write: sql`SELECT * FROM users`","cause":"Using tagged template without backticks or forgetting the tag","error":"SyntaxError: Unexpected template string"},{"fix":"Use: import sql from 'embrace-sql'","cause":"Importing named export instead of default","error":"TypeError: sql is not a function"},{"fix":"Run: npm install embrace-sql","cause":"Package not installed or not in node_modules","error":"Cannot find module 'embrace-sql'"}],"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/jzimmek/embrace-sql#readme","github":"https://github.com/jzimmek/embrace-sql","docs":null,"changelog":null,"pypi":null,"npm":"embrace-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}}