Registry / database / sequencework-sql-global

sequencework-sql-global

JSON →
library2.4.1jsnpmunverified

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.

npm install sequencework-sql-global
INSTALL
IMPORT
SIG · SEQUENCEWORK-SQL-G
S
sequencework-sql-global
databasejavascriptv2.4.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (sql function)
import sql from 'sequencework-sql-global'
const sql = require('sequencework-sql-global')
ESM default import preferred. CommonJS require also works.
sql.raw
import sql from 'sequencework-sql-global'; sql.raw('table')
import { raw } from 'sequencework-sql-global'
sql.raw is a property on the default export, not a named export.
SqlTaggedQuery type
import type { SqlTaggedQuery } from 'sequencework-sql-global'
TypeScript type export for the return type of the sql tag.
global SQL symbol (if needed for type checks)
import { SQL_GLOBAL } from 'sequencework-sql-global'
Exported symbol used for duck-type checking; not for normal usage.

Demonstrates basic usage with node-postgres: template literal with parameters, async query execution.

import sql from 'sequencework-sql-global'; import { Pool } from 'pg'; const pool = new Pool(); async function getMovies(minYear, maxYear) { const query = sql` SELECT * FROM movies WHERE year >= ${minYear} AND year <= ${maxYear} `; const { rows } = await pool.query(query); return rows; } getMovies(1990, 1999).then(console.log).catch(console.error);
Debug
Known issues
gotchaConditional expressions that evaluate to `false` are NOT ignored; they become a value in the query. Use ternary or explicit `undefined`.
fix
Use `condition ? sql\`...\` : undefined` instead of `condition && sql\`...\``.
affects: >=1.0.0
gotchaPassing `sql.raw` with user input can lead to SQL injection. Only use with trusted strings.
fix
Never pass unsanitized user input to `sql.raw`. Validate or use parameterized queries.
affects: >=1.0.0
breakingIn 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.
fix
Upgrade to version 2.x (this fork) or ensure only one version is installed.
affects: <2.0.0
gotchaThe `sql` tag returns an object with `text` and `values` properties. Directly interpolating the result into another template literal does not work as expected.
fix
Use the result directly with `pg.query()` or similar. Do not combine sql-tagged literals manually.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: SQL is not a constructor
Trying to instantiate `sql` as a class (e.g., `new sql\`...\``) instead of using it as a template tag.
fix
Use `sql\`...\`` (template literal tag) without `new`.
Cannot read property 'raw' of undefined
Importing a named export `{ sql }` instead of default import.
fix
Use `import sql from 'sequencework-sql-global'` or `const sql = require('sequencework-sql-global')`.
Error: Expected "sql" to be a function, got object
Using `require('sequencework-sql-global')` in an ES module context where default export is not a function.
fix
Use `import sql from 'sequencework-sql-global'` in ES modules, or use `const { default: sql } = require('sequencework-sql-global')` for CommonJS interop.
Upgrade
Version history
2.4.1latest on npm
Audit
Dependencies
pgoptionalOptional peer dependency; required if using with node-postgres directly.
Agent activity
12 hits · last 30 days
node
10
Meta
2
Resources
sequencework-sql-global — npm install sequencework-sql-global · libregistry