SQL Template Tag
npm install sql-template-tag --save
;;query.sql; //=> "SELECT * FROM books WHERE id = ?"query.text; //=> "SELECT * FROM books WHERE id = $1"query.values; //=> [id]pg.queryquery; // Uses `text` and `values`.mysql.queryquery; // Uses `sql` and `values`.// Embed SQL instances inside SQL instances.;;// Join and "empty" helpers (useful for nested queries).sql`SELECT * FROM books `;
The main difference between this module and others is first-class TypeScript. There's also the
empty helpers. Specific differences are documented below:
Promotes mutation via chained methods and lacks nesting SQL statements. The idea to support both
pg compatibility came from here.
Missing TypeScript and MySQL support. This is the API I envisioned before starting development and, by supporting
pg only, it has the ability to dedupe
values. Supporting MySQL makes deduping impossible, because of
? placeholders instead of
$<num>, so I decided that was a premature optimisation here and opted to keep
mysql support here instead.