Registry / database / sql-tag

sql-tag

JSON →
library1.0.1jsnpmunverified

A template tag for writing elegant parameterized SQL queries using ES2015 tagged template literals. Current stable version is 1.0.1, with a maintenance-only release cadence. It outputs a structured object with the SQL query string and its values, directly compatible with pg, mysql, mysql2, and sequelize (via sequelize-sql-tag). Key differentiators: lightweight, zero dependencies, framework-agnostic, but does not provide escaping safety. Last released in 2018.

npm install sql-tag
INSTALL
IMPORT
SIG · SQL-TAG
S
sql-tag
databasejavascriptv1.0.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.

sql
const sql = require('sql-tag');
CommonJS usage. No ESM exports available.
sql
import sql from 'sql-tag';
import { sql } from 'sql-tag';
Default export only; named import will result in undefined.

Create a parameterized SQL query with a template tag and use it with pg.

const sql = require('sql-tag'); const { Client } = require('pg'); const client = new Client(); await client.connect(); const userId = 'foo'; const query = sql`SELECT * FROM users WHERE id = ${userId}`; console.log(query.sql); // 'SELECT * FROM users WHERE id = ?' console.log(query.query); // 'SELECT * FROM users WHERE id = $1' console.log(query.values); // ['foo'] const res = await client.query(query); console.log(res.rows);
Debug
Known issues
gotchasql-tag does not provide any escaping safety; it only structures the query and values. SQL injection is possible if you concatenate user input directly.
fix
Always use parameterized queries via the sql tag; never interpolate raw strings into the template literal.
affects: <=1.0.1
deprecatedThe package has not been updated since 2018 and may not support newer Node.js versions beyond 4.
fix
Consider using a more actively maintained library like squel or knex.
affects: <=1.0.1
Errors
Common errors & fixes
Cannot find module 'sql-tag'
The package is not installed or typo in package name.
fix
Run 'npm install sql-tag' and ensure import path is correct.
TypeError: sql is not a function
Using named import { sql } instead of default import.
fix
Use 'import sql from 'sql-tag'' or 'const sql = require('sql-tag')'.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
12
Meta
2
OpenAI (training)
1
Resources
sql-tag — npm install sql-tag · libregistry