SQLSyntax is a JavaScript/TypeScript library for composing SQL queries using tagged template literals, ported from ScalikeJDBC. Version 2.0.1 is the latest stable release. It provides a SQLSyntax class and sqls template tag that automatically escapes interpolated values and generates parameterized queries, preventing SQL injection for safe values. Key differentiators include the ability to merge SQLSyntax instances directly into queries, a custom toQuery function for adapting to different databases (default PostgreSQL), and a createUnsafely method for dynamic identifiers with explicit safety warnings. The library is ESM-only since v2.0.0 and requires Node.js >=18. It ships TypeScript types and is published on npm.
npm install sql-syntaxNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a parameterized SELECT query using sqls tag and executes it with pg client.
Switch to ESM (use import) or upgrade to Node.js >=18. Alternatively, stay on v1.x if CommonJS is needed.
Consider extending the SQLSyntax class instead: class CustomSQLSyntax extends SQLSyntax { toQuery() {...} }.Do not use createUnsafely with untrusted input. Always validate and sanitize identifier strings manually.
Set SQLSyntax.customToQueryFunc to a function that produces the correct placeholder style for your database.
Add "type": "module" to package.json or rename file to .mjs. Upgrade to Node.js >=18.
Change to dynamic import: const { default: SQLSyntax } = await import('sql-syntax'); or switch to ESM.Run npm install sql-syntax. Ensure tsconfig.json has "moduleResolution": "node16" or "nodenext".
Use the sqls tagged template literal: const query = sqls`SELECT * FROM users`; then query.toQuery().
No dependency data recorded yet.