Registry / database / sql-lint

sql-lint

JSON →
library1.0.2jsnpmunverified

An intelligent SQL linter that performs sanity checks (e.g., missing WHERE, unmatched parentheses) and surfaces database errors with more informative messages. The current stable version is 1.0.2. Since v1.0.0, it has been considered stable. Compared to other SQL linters, sql-lint focuses on catching common mistakes like missing WHERE clauses and invalid DROP/CREATE options, and supports multiple databases (MySQL, PostgreSQL). It can be used as a CLI tool or programmatically in JavaScript/TypeScript, and ships TypeScript type definitions. Release cadence is irregular.

npm install sql-lint
INSTALL
IMPORT
SIG · SQL-LINT
S
sql-lint
databasejavascriptv1.0.2
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.

sqlLint
import sqlLint from 'sql-lint'
const sqlLint = require('sql-lint')
ESM default import. Default export is a function. TypeScript type definitions are included.
sqlLint
const sqlLint = require('sql-lint').default || require('sql-lint')
const sqlLint = require('sql-lint')
In CommonJS, the default export is under .default if the package uses ESM. Use the dual approach to be safe.
SqlLintOptions
import type { SqlLintOptions } from 'sql-lint'
import { SqlLintOptions } from 'sql-lint'
Use type import for TypeScript to avoid runtime overhead.

Shows programmatic usage to lint SQL string and handle lint errors.

import sqlLint from 'sql-lint'; const errors = await sqlLint({ sql: 'DELETE FROM users WHERE id = 1;', // optionally connect to a database to get server errors // host: 'localhost', // user: 'root', // password: process.env.DB_PASS ?? '' }); if (errors.length === 0) { console.log('No errors found.'); } else { for (const error of errors) { console.log(`${error.file}:${error.line}: ${error.message}`); } }
sql-lint --version
Debug
Known issues
gotchaThe default export is a function. CommonJS require() may need .default to access the default export.
fix
Use require('sql-lint').default or use ESM imports.
affects: >=1.0.0
breakingIn v0.0.14, the --file and -f flags were removed. Files are now passed as positional arguments.
fix
Use `sql-lint my-file.sql` instead of `sql-lint -f my-file.sql`.
affects: >=0.0.14
deprecatedThe --query and -q flags are deprecated in v0.0.14 and may be removed. Use `sql-lint --sql 'SELECT 1'` or pass via stdin.
fix
Use `echo 'SELECT 1' | sql-lint` or programmatic API.
affects: >=0.0.14 <1.0.0
gotchaWhen used programmatically, unresolved promises could cause the process to hang in versions before v0.0.20.
fix
Update to v0.0.20 or later.
affects: <0.0.20
gotchaConfig file `ignore-errors` option was not respected until v0.0.20.
fix
Update to v0.0.20 or later.
affects: <0.0.20
Errors
Common errors & fixes
TypeError: sqlLint is not a function
Using require('sql-lint') which returns an object with a .default property.
fix
Use `const sqlLint = require('sql-lint').default;` or switch to ESM imports.
Error: Cannot find module 'sql-lint'
Package not installed globally or locally.
fix
Run `npm install -g sql-lint` for CLI use or `npm install sql-lint` for programmatic use.
sql-lint: unable to connect to database
Database connection parameters are missing or incorrect.
fix
Provide correct host, user, password, and database options in the config or programmatic call.
SyntaxError: Unexpected token: name, (something) (line: 1, col: 1)
The SQL string contains non-SQL content or is not a valid query.
fix
Ensure the input is a valid SQL statement. Use the programmatic API with `sql` option.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
mysqloptionalUsed for connecting to MySQL databases to fetch server errors.
pgoptionalUsed for connecting to PostgreSQL databases to fetch server errors.
Agent activity
17 hits · last 30 days
node
14
Meta
1
OpenAI (training)
1
Resources
sql-lint — npm install sql-lint · libregistry