Registry / database / sql-minifier

sql-minifier

JSON →
library1.0.0jsnpmunverified

A lightweight npm package for minifying SQL statements by removing unnecessary whitespace and comments. Version 1.0.0, released recently, with no known release cadence. Handles single-line and multi-line comments, optionally preserves comments in condensed form, and detects unclosed strings/comments throwing errors. Performs minification in a single pass for efficiency. Minimal API surface with one main function.

npm install sql-minifier
INSTALL
IMPORT
SIG · SQL-MINIFIER
S
sql-minifier
databasejavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

minifySQL
const { minifySQL } = require('sql-minifier');
import { minifySQL } from 'sql-minifier';
Package uses CommonJS; ESM import may fail in Node unless using ES module resolution (e.g., .mjs file).
default import
const sqlMinifier = require('sql-minifier'); const minified = sqlMinifier.minifySQL(sql);
const minifySQL = require('sql-minifier');
Do not assign require directly to minifySQL; it is a named export, not the default.
minifySQL with options
const { minifySQL } = require('sql-minifier'); const minified = minifySQL(sql, { includeComments: true });
const minified = minifySQL(sql, true);
Options must be passed as an object, not a bare boolean.

Installs sql-minifier, minifies a SQL string with and without preserving comments, showing both outputs.

const { minifySQL } = require('sql-minifier'); const originalSQL = `SELECT * FROM users WHERE id = 1; -- comment`; const minifiedWithoutComments = minifySQL(originalSQL); console.log(minifiedWithoutComments); // Output: 'SELECT * FROM users WHERE id=1;' const minifiedWithComments = minifySQL(originalSQL, { includeComments: true }); console.log(minifiedWithComments); // Output: 'SELECT * FROM users WHERE id=1; /*comment*/'
Debug
Known issues
gotchaThe package does not support ES module imports (ESM). Using `import { minifySQL } from 'sql-minifier'` will fail unless the importing project uses CommonJS or Node's experimental ESM interop.
fix
Use `const { minifySQL } = require('sql-minifier')` or configure your project to use CommonJS.
affects: 1.0.0
gotchaOptions must be passed as an object (e.g., `{ includeComments: true }`), not a boolean directly. Passing a boolean will be interpreted as a string with length.
fix
Always pass options as an object: `minifySQL(sql, { includeComments: true })`.
affects: 1.0.0
gotchaThe minifier removes newlines and multiple spaces, which may break SQL syntax that relies on whitespace (e.g., BETWEEN, IN lists). Not a bug, but a design choice.
fix
Ensure your SQL does not depend on whitespace for parsing; write standard SQL that is whitespace-agnostic.
affects: 1.0.0
gotchaComments inside string literals will be preserved but may be misinterpreted if the minifier encounters unescaped quotes. The minifier does not fully parse SQL strings; it only detects string delimiters.
fix
Ensure string literals are properly escaped; avoid containing comment tokens inside strings that could confuse the minifier.
affects: 1.0.0
Errors
Common errors & fixes
TypeError: (0 , require(...).minifySQL) is not a function
Incorrect import: using default import with `const minifySQL = require('sql-minifier')` when minifySQL is a named export.
fix
Use destructuring: `const { minifySQL } = require('sql-minifier')`.
SyntaxError: Unexpected token 'export'
Trying to use ES module import syntax in a CommonJS file without type:module.
fix
Use require or rename file to .mjs and ensure package.json has type:module.
minifySQL is not defined
Using `const minifySQL = require('sql-minifier').minifySQL` incorrectly or misspelling.
fix
Use `const { minifySQL } = require('sql-minifier')`.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
12
Meta
2
OpenAI (training)
1
Resources
sql-minifier — npm install sql-minifier · libregistry