{"id":46434,"library":"sql-compose","title":"SQL Compose","description":"SQL Compose (v2.4.5) is a lightweight JavaScript library for building parameterized SQL queries using function composition and string interpolation. Released in 2019, it follows a semver cadence with infrequent updates. It differentiates from raw template literals and ORMs by offering safe interpolation via wrapper functions, automatic parameter numbering, and support for nested thunks. The library is ESM-only and provides TypeScript definitions. Alternatives like sql-template-strings or squel offer similar functionality but with different API designs.","status":"active","version":"2.4.5","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install sql-compose","lang":"bash","label":"npm"},{"cmd":"yarn add sql-compose","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-compose","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only since v2; CJS require will throw.","wrong":"const { build } = require('sql-compose')","symbol":"build","correct":"import { build } from 'sql-compose'"},{"note":"config is a named export, not default.","wrong":"import config from 'sql-compose'","symbol":"config","correct":"import { config } from 'sql-compose'"},{"note":"auto is a named export; CJS require fails in ESM-only package.","wrong":"const { auto } = require('sql-compose')","symbol":"auto","correct":"import { auto } from 'sql-compose'"}],"quickstart":{"code":"import { build, config, auto } from 'sql-compose';\n\nconfig.formatFn = x => `%(${x})s`;\n\nconst autoQuery = (opts) => (w) => auto(w)`\n    val > ${ opts.min_val }\n`;\n\nconst query = (opts) => (w) => `\n    SELECT * FROM table\n    WHERE id IN (${ opts.ids.map(w).join(',') })\n    AND val < ${ w(opts.max_val) }\n    AND ${ w(autoQuery(opts)) }\n`;\n\nconst opts = { ids: [1, 2, 3], max_val: 8, min_val: 5 };\nconst [sql, params] = build(query(opts));\nconsole.log(sql, params);","lang":"javascript","description":"Builds a parameterized SQL query with dynamic IN clause and nested thunk using auto wrapper."},"warnings":[{"fix":"Use import statements instead of require().","message":"package.json 'type' field set to 'module' in v2; CommonJS require() results in ERR_REQUIRE_ESM","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always invoke w(value) to interpolate a scalar; use auto(w) for tagged template literals.","message":"Wrapper function must be called directly (e.g., w(value)), not used as a template tag","severity":"gotcha","affected_versions":"all"},{"fix":"Call auto(w)`...` directly; do not assign auto(w) to a variable and try to reuse it as a wrapper.","message":"The auto wrapper returns a string, not a function; cannot be used further as a wrapper","severity":"gotcha","affected_versions":"all"},{"fix":"Apply custom formatting via build() second argument if available, or avoid global config.","message":"config.formatFn is a global mutable setting that affects all subsequent builds; deprecated in favor of per-query options","severity":"deprecated","affected_versions":">=2.4.0"}],"env_vars":null,"search_vec":"'2019':24 'altern':66 'api':80 'automat':48 'build':12 'cadenc':29 'compos':2,4 'composit':18 'definit':65 'design':81 'differ':79 'differenti':34 'esm':60 'esm-on':59 'follow':26 'function':17,47,76 'infrequ':31 'interpol':21,44 'javascript':9,82 'librari':10,57 'lightweight':8 'like':67 'liter':38 'nest':54 'number':50 'offer':42,74 'orm':40 'paramet':49 'parameter':13 'provid':63 'queri':15 'raw':36 'releas':22 'safe':43 'semver':28 'similar':75 'sql':1,3,14,69 'sql-template-str':68 'squel':73 'string':20,71 'support':52 'templat':37,70 'thunk':55 'typescript':64 'updat':32 'use':16 'v2.4.5':5 'via':45 'wrapper':46","created_at":"2026-06-07T12:59:54.196380+00:00","updated_at":"2026-06-07T12:59:54.196380+00:00","problems":[{"fix":"Switch to import syntax or change your project to ESM.","cause":"Package is ESM-only since v2; using require() in CommonJS project.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/sql-compose/index.js not supported."},{"fix":"Use auto(w)`...` as a tagged template literal, not w(...).","cause":"Using auto(w) as a wrapper function instead of calling auto(w)`...` directly.","error":"TypeError: w is not a function"},{"fix":"Ensure all imports are static and at the top of the file.","cause":"Circular dependency or incorrect import order when mixing ESM and CJS.","error":"ReferenceError: Cannot access 'build' before initialization"}],"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-compose","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-07","next_check":"2026-09-05","install_tag":null}}