A MySQL query builder and SQL string formatting library that provides template literal-based SQL escaping and object-to-SQL conversion. Current stable version is 2.1.0. It wraps sqlstring for escaping and offers helper functions like insert, where, set, and values to safely build SQL from JavaScript objects. Key differentiators include automatic detection of template usage (e.g., objects become WHERE or SET clauses) and a prefix '#' to bypass escaping for trusted strings. Release cadence is low; the package is maintained primarily for personal use with notable limitations in documentation consistency.
npm install sql-fmtNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates template literal SQL building with auto-escape, object handling for WHERE/INSERT/SET, and direct escape/escapeId functions.
Avoid using '#' with user-supplied data; always prefer automatic escaping.
Use explicit sql.where() if you need precise control over condition grouping.
Use sql.insert() for INSERT queries; sql.values() is intended for VALUES portion only.
Cast query strings as needed or supplement with your own type definitions.
Use a bundler who provides Buffer polyfill (e.g., webpack with Buffer plugin) or avoid runtime usage in browser.
Use the default import: import sql from 'sql-fmt', then call sql.escape().