{"id":43819,"library":"sequencework-sql-global","title":"sequencework-sql-global","description":"A JavaScript/TypeScript template literal tag that formats SQL queries into {text, values} objects compatible with node-postgres. Version 2.4.1 is the current stable release. This is a fork of @sequencework/sql that adds global support by fixing `instanceof` behavior across multiple `require` calls via a type tag. Key differentiators: lightweight (~50 lines), 100% test coverage, supports nested tags and conditional expressions, and includes helpers like `sql.raw` for unescaped values. Released infrequently, primarily bug fixes.","status":"active","version":"2.4.1","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","sql","template-literals","node-postgres","pg","typescript"],"install":[{"cmd":"npm install sequencework-sql-global","lang":"bash","label":"npm"},{"cmd":"yarn add sequencework-sql-global","lang":"bash","label":"yarn"},{"cmd":"pnpm add sequencework-sql-global","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Optional peer dependency; required if using with node-postgres directly.","package":"pg","optional":true}],"imports":[{"note":"ESM default import preferred. CommonJS require also works.","wrong":"const sql = require('sequencework-sql-global')","symbol":"default (sql function)","correct":"import sql from 'sequencework-sql-global'"},{"note":"sql.raw is a property on the default export, not a named export.","wrong":"import { raw } from 'sequencework-sql-global'","symbol":"sql.raw","correct":"import sql from 'sequencework-sql-global'; sql.raw('table')"},{"note":"TypeScript type export for the return type of the sql tag.","wrong":"","symbol":"SqlTaggedQuery type","correct":"import type { SqlTaggedQuery } from 'sequencework-sql-global'"},{"note":"Exported symbol used for duck-type checking; not for normal usage.","wrong":"","symbol":"global SQL symbol (if needed for type checks)","correct":"import { SQL_GLOBAL } from 'sequencework-sql-global'"}],"quickstart":{"code":"import sql from 'sequencework-sql-global';\nimport { Pool } from 'pg';\n\nconst pool = new Pool();\n\nasync function getMovies(minYear, maxYear) {\n  const query = sql`\n    SELECT * FROM movies\n    WHERE year >= ${minYear} AND year <= ${maxYear}\n  `;\n  const { rows } = await pool.query(query);\n  return rows;\n}\n\ngetMovies(1990, 1999).then(console.log).catch(console.error);","lang":"typescript","description":"Demonstrates basic usage with node-postgres: template literal with parameters, async query execution."},"warnings":[{"fix":"Use `condition ? sql\\`...\\` : undefined` instead of `condition && sql\\`...\\``.","message":"Conditional expressions that evaluate to `false` are NOT ignored; they become a value in the query. Use ternary or explicit `undefined`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Never pass unsanitized user input to `sql.raw`. Validate or use parameterized queries.","message":"Passing `sql.raw` with user input can lead to SQL injection. Only use with trusted strings.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to version 2.x (this fork) or ensure only one version is installed.","message":"In previous versions (pre-fork), the `instanceof` check failed when using multiple copies of the package. This fork adds a global type tag to fix that.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"Use the result directly with `pg.query()` or similar. Do not combine sql-tagged literals manually.","message":"The `sql` tag returns an object with `text` and `values` properties. Directly interpolating the result into another template literal does not work as expected.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'100':57 '2.4.1':24 '50':55 'across':44 'add':37 'behavior':43 'bug':77 'call':47 'compat':18 'condit':64 'coverag':59 'current':27 'differenti':53 'express':65 'fix':41,78 'fork':33 'format':11 'global':4,38 'helper':68 'includ':67 'infrequ':75 'instanceof':42 'javascript':79 'javascript/typescript':6 'key':52 'lightweight':54 'like':69 'line':56 'liter':8,83 'multipl':45 'nest':61 'node':21,85 'node-postgr':20,84 'object':17 'pg':87 'postgr':22,86 'primarili':76 'queri':13 'releas':29,74 'requir':46 'sequencework':2 'sequencework-sql-glob':1 'sequencework/sql':35 'sql':3,12,80 'sql.raw':70 'stabl':28 'support':39,60 'tag':9,51,62 'templat':7,82 'template-liter':81 'test':58 'text':15 'type':50 'typescript':88 'unescap':72 'valu':16,73 'version':23 'via':48","created_at":"2026-06-05T17:01:37.987569+00:00","updated_at":"2026-06-05T17:01:37.987569+00:00","problems":[{"fix":"Use `sql\\`...\\`` (template literal tag) without `new`.","cause":"Trying to instantiate `sql` as a class (e.g., `new sql\\`...\\``) instead of using it as a template tag.","error":"TypeError: SQL is not a constructor"},{"fix":"Use `import sql from 'sequencework-sql-global'` or `const sql = require('sequencework-sql-global')`.","cause":"Importing a named export `{ sql }` instead of default import.","error":"Cannot read property 'raw' of undefined"},{"fix":"Use `import sql from 'sequencework-sql-global'` in ES modules, or use `const { default: sql } = require('sequencework-sql-global')` for CommonJS interop.","cause":"Using `require('sequencework-sql-global')` in an ES module context where default export is not a function.","error":"Error: Expected \"sql\" to be a function, got object"}],"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":"sequencework-sql-global","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}}