sql-stamp is a tiny SQL templating library (v0.8.0) focused on simplicity and keeping SQL clean and readable. It supports conditional placeholders (`{=key, default}` for parameterized values, `{!key}` for raw values), ternary switches (`{?key, truthy, falsey}`), and file inclusion (`{>path}`). It automatically converts most placeholders to `?` for injection-safe parameterized queries. Unlike HTML template engines, it avoids loops and complex conditionals. Release cadence is low; last commit was 2019. Key differentiator: it outputs both SQL string and args array, integrating well with database drivers.
npm install sql-stampNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic usage: loading templates, calling a template with data, and destructuring the result into sql string and args array.
Use await or .then() on the return value of sqlStamp().
Set {prettyErrors: true} explicitly if you want detailed error locations.Avoid user-provided data with {!key}. For user input, use {=key} for parameterized queries.Use absolute paths or ensure the cwd is set correctly.
Wrap in async function or use .then().
In CommonJS: const sqlStamp = require('sql-stamp'); (no .default). In ESM: import sqlStamp from 'sql-stamp';const tmpl = await sqlStamp(templates); or use .then().
Check the number of placeholders and the data object keys match exactly.
Use absolute paths or set the current working directory correctly. Include directive paths are relative to cwd.