Registry / database / sql-parse

sql-parse

JSON →
library0.1.5jsnpmunverified

`sql-parse` is an unmaintained JavaScript utility for parsing basic SQL queries, with its last known stable version being 0.1.5, published in June 2015. It was designed to provide a simple programmatic interface for tokenizing and parsing SQL strings, extracting components like `SELECT` statements and `WHERE` clauses, including initial support for `OR` operators. Due to its age and lack of maintenance for nearly a decade, it is considered abandoned. Modern SQL dialects, advanced query features, and contemporary JavaScript module systems (ESM) are not supported. Developers seeking robust, actively maintained SQL parsing solutions for diverse database systems (e.g., MySQL, PostgreSQL, BigQuery, Snowflake, FlinkSQL) should consider alternatives like `node-sql-parser`, `dt-sql-parser`, or `@casual-simulation/sql-parser`. Its release cadence was sporadic and ceased many years ago. It lacks official TypeScript types and has no external runtime dependencies.

npm install sql-parse
INSTALL
IMPORT
SIG · SQL-PARSE
S
sql-parse
databasejavascriptv0.1.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

parse
const { parse } = require('sql-parse');
import { parse } from 'sql-parse';
The package is CommonJS-only and does not support ES Modules. Using 'import' will result in a module resolution error.
Full module import (for completeness, though `parse` is usually destructured)
const sqlParse = require('sql-parse');
Access the parse function via `sqlParse.parse`. This approach is less common but equally valid for CommonJS.

Demonstrates importing and using the `parse` function to process a basic SQL `SELECT` statement in a CommonJS environment. It also highlights potential issues with unsupported syntax due to the package's age.

const { parse } = require('sql-parse'); const simpleSelect = 'SELECT id, name FROM users WHERE active = true OR age > 30;'; const insertStatement = 'INSERT INTO products (name, price) VALUES ("Laptop", 1200.00);'; const updateStatement = 'UPDATE orders SET status = "shipped" WHERE id = 101;'; try { const resultSelect = parse(simpleSelect); console.log('Parsed SELECT:', JSON.stringify(resultSelect, null, 2)); // Note: The specific structure of `result` depends entirely on the library's implementation. // Given its age, it might be a simple object or array of tokens/nodes. // This example assumes a structure that might expose `statements` or similar. if (resultSelect && Array.isArray(resultSelect.statements) && resultSelect.statements.length > 0) { console.log('First statement type:', resultSelect.statements[0].type); // e.g., 'SELECT' } else { console.log('Could not determine statement type for SELECT.'); } // Trying other statement types might fail or yield unexpected results // as the README primarily focuses on SELECT queries. // const resultInsert = parse(insertStatement); // console.log('Parsed INSERT:', JSON.stringify(resultInsert, null, 2)); } catch (error) { console.error('SQL Parsing Error:', error.message); console.warn('This package is very old and may not support modern or complex SQL syntax.'); }
Debug
Known issues
breakingThe `sql-parse` package is abandoned and has not been updated since June 2015. It no longer receives bug fixes, security patches, or feature enhancements. Continued use in production environments is highly discouraged due to significant security risks and compatibility issues with modern JavaScript runtimes and evolving SQL standards.
fix
Migrate your application to a actively maintained and modern SQL parsing library, such as `node-sql-parser`, `dt-sql-parser`, `@casual-simulation/sql-parser`, or `js-sql-parser`.
affects: >=0.1.0
gotchaThis package is strictly CommonJS (`require`) and does not support ES Modules (`import/export`). Attempting to use `import` syntax will result in module resolution errors.
fix
Ensure all imports for this package use `const { parse } = require('sql-parse');` syntax within a CommonJS environment. For projects primarily using ESM, a full migration to a modern parser is recommended.
affects: >=0.1.0
gotchaThe parser has limited support for SQL dialects and modern SQL syntax. It was designed for basic `SELECT` statements and early SQL standards. Complex queries, specific database dialect features (e.g., PostgreSQL JSON functions, MySQL `WITH` clauses), or advanced DDL/DML operations are likely to cause parse errors or unexpected results.
fix
Thoroughly test the parser with your specific SQL queries. For comprehensive and dialect-specific SQL parsing, switch to a more actively developed library that explicitly supports various SQL dialects.
affects: >=0.1.0
gotchaThe `sql-parse` package does not ship with TypeScript declaration files (`.d.ts`). Using it in a TypeScript project will result in implicitly typed `any` or require manual type definitions, reducing type safety.
fix
If migration is not immediately feasible, create a custom `sql-parse.d.ts` file with basic type declarations. However, the recommended solution is to migrate to a modern SQL parser that provides built-in TypeScript support.
affects: >=0.1.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Attempting to use ES Module `import` syntax (`import { parse } from 'sql-parse';`) in a JavaScript file that is not configured as an ES module, or with this CommonJS-only package.
fix
Change the import statement to `const { parse } = require('sql-parse');`.
TypeError: (0, _sqlParse.parse) is not a function
This error often occurs when a CommonJS package's exports are incorrectly accessed in an ES Module context, or if the `sql-parse` module itself is imported incorrectly.
fix
Ensure you are using CommonJS `require` syntax: `const { parse } = require('sql-parse');`. Verify that `sql-parse` is installed and the path is correct.
Parse error at line X, column Y: Unexpected token Z
The input SQL query contains syntax elements, keywords, or structures that the old `sql-parse` library does not recognize or support. This is common with modern SQL features or database-specific extensions.
fix
Review the problematic SQL statement for advanced features or dialect-specific syntax. If the query is complex or uses modern SQL, consider migrating to a more robust and actively maintained SQL parser.
Upgrade
Version history
0.1.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
8
Meta
2
OpenAI (training)
1
Resources
sql-parse — npm install sql-parse · libregistry