tagged-sql is a lightweight JavaScript/TypeScript library (v0.9.0, stable) that leverages ES6 tagged template literals for writing SQL statements. It supports table name prefixes, separate field and table references via TaggedSql.Table and TaggedSql.Field, and flexible placeholder building for PostgreSQL and MySQL. Unlike other template SQL libraries, it provides a build() method that lets you control placeholder syntax (e.g., $1 for Postgres, ? for MySQL) and a transform() method for prefixing table names. The package ships with TypeScript definitions and has minimal dependencies.
npm install tagged-sqlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage: creating a TaggedSql query with template literals, building query strings with placeholder generators (PostgreSQL $1, MySQL ?), and using Table/Field for prefix-safe identifiers.
Use sql.build((value, index) => `$${index+1}`) for Postgres or sql.build('?') for MySQL.Use TaggedSql.Table('table') and TaggedSql.Field('field', table).Always use parameterized queries: sql.build(...) for the text and pass sql.values to the database driver.
Use .transform((v, t, g) => t !== 'table' || g ? v : 'prefix_' + v).
Use import TaggedSql from 'tagged-sql' (without braces).
Ensure you have imported TaggedSql correctly and call TaggedSql.Table (capital T).
Check that the variable contains a Sql object: const sql = TaggedSql`SELECT * FROM table`; then sql.build(...).