Simple SQL escape and format utility for MySQL, commonly used as a dependency of mysqljs/mysql and mysql2. The current stable version is 2.3.3, with a stable release cadence (last updated 2020). It provides escape() and format() methods for safe SQL value interpolation, supporting custom toSqlString for raw SQL fragments. Unlike template-based libraries, it uses placeholder substitution (?), but does NOT protect against all injection vectors (e.g., NO_BACKSLASH_ESCAPES mode). Lightweight, no dependencies, and compatible with Node >= 0.6.
npm install sqlstringNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates escape, format, and raw usage for safe SQL value interpolation and raw SQL fragments.
Ensure MySQL server runs with NO_BACKSLASH_ESCAPES disabled, or use parameterized queries with mysql2 prepared statements.
Avoid using '?' inside comment blocks or string literals; escape literal '?' or use alternative methods.
Use mysql2's escape() or migrate to a maintained alternative like @mysql2/promise.
Validate numeric inputs to reject NaN/Infinity before passing to escape/format.
Ensure objects used with escape/format have only serializable values.
Use default import: `import SqlString from 'sqlstring'` then call `SqlString.escape(value)`.
Require correctly: `const SqlString = require('sqlstring');` or default import in ESM.Use `SqlString.raw('...')` to create an object with toSqlString method.No dependency data recorded yet.