sql-template-strings (v2.2.2) is a mature, stable library that enables ES6 tagged template literals for building prepared SQL statements. It supports mysql, mysql2, pg (PostgreSQL), and Sequelize, automatically generating the correct placeholder syntax ($1, ?) and extracting values into arrays. Unlike raw template strings or manual concatenation, it prevents SQL injection by separating query text and values. Ships TypeScript definitions. Minimal API surface (SQL tag and append method). Last updated 2020; no active development but widely used and bug-free for its scope.
npm install sql-template-stringsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to use the SQL tagged template to create a prepared statement and execute it with mysql2 using async/await.
Keep all dynamic values as direct template interpolations, not inside quoted substrings.
Use query.sql or query.text for the query string and query.values for the parameters, or use compatible drivers (mysql, mysql2, pg) that accept the object directly.
Use the append() method to build queries dynamically instead of concatenating strings.
Use query.sql for MySQL-style (?) placeholders and query.text for PostgreSQL-style ($1) placeholders.
Use the backtick syntax: SQL`...`
Chain .append() correctly: query.append(SQL`...`)
Use default import: import SQL from 'sql-template-strings' or require: const SQL = require('sql-template-strings')No dependency data recorded yet.