The `sql-parser` package provides a JavaScript-based lexer and parser specifically designed for SQL syntax. As of version 0.5.0, it is primarily capable of tokenizing and parsing fairly basic `SELECT` queries, offering functionalities like `WHERE`, `GROUP BY`, `ORDER BY`, and `LIMIT` clause parsing. The lexer outputs tokens in a format compatible with JISON, which the parser then consumes to produce a `Select` object. A notable feature is the ability to reconstruct a well-formatted SQL string from the parsed object via its `.toString()` method. The project appears to be in a largely unmaintained state, with no indication of active development towards comprehensive SQL support or regular releases since its initial limited scope. Its implementation borrowed heavily from CoffeeScript project boilerplate, suggesting an older codebase that predates modern JavaScript module patterns and extensive TypeScript adoption.
npm install sql-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates tokenizing a basic SELECT query, parsing it into a 'Select' object, and then re-generating a formatted SQL string.
Do not use this parser for comprehensive or production-grade SQL parsing. Consider alternatives like `node-sql-parser` or `dt-sql-parser` for broader SQL dialect support.
Avoid using in new projects requiring active maintenance, security updates, or ongoing feature development. Be aware of potential unpatched vulnerabilities if used with untrusted inputs.
Ensure you use `require()` syntax for importing the package: `const { lexer, parser } = require('sql-parser');`. If using TypeScript with ESM, ensure your `tsconfig.json` and `package.json` are configured for CJS output or use dynamic `import()`.Manual type declarations (`.d.ts` files) would be required to leverage TypeScript's benefits. For typed SQL parsers, explore more modern alternatives.
Ensure you are using `const { lexer } = require('sql-parser');` or `const sqlParser = require('sql-parser'); const lexer = sqlParser.lexer;`.Simplify the SQL query to only basic SELECT statements with supported clauses (WHERE, GROUP BY, ORDER BY, LIMIT) or use a more robust SQL parsing library if full SQL support is needed.
Change the import statement to CommonJS `require()`: `const { lexer } = require('sql-parser');`.No dependency data recorded yet.