{"id":17955,"library":"sql-parse","title":"SQL Parsing Utility","description":"`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.","status":"abandoned","version":"0.1.5","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","sql","parser"],"install":[{"cmd":"npm install sql-parse","lang":"bash","label":"npm"},{"cmd":"yarn add sql-parse","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-parse","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is CommonJS-only and does not support ES Modules. Using 'import' will result in a module resolution error.","wrong":"import { parse } from 'sql-parse';","symbol":"parse","correct":"const { parse } = require('sql-parse');"},{"note":"Access the parse function via `sqlParse.parse`. This approach is less common but equally valid for CommonJS.","symbol":"Full module import (for completeness, though `parse` is usually destructured)","correct":"const sqlParse = require('sql-parse');"}],"quickstart":{"code":"const { parse } = require('sql-parse');\n\nconst simpleSelect = 'SELECT id, name FROM users WHERE active = true OR age > 30;';\nconst insertStatement = 'INSERT INTO products (name, price) VALUES (\"Laptop\", 1200.00);';\nconst updateStatement = 'UPDATE orders SET status = \"shipped\" WHERE id = 101;';\n\ntry {\n  const resultSelect = parse(simpleSelect);\n  console.log('Parsed SELECT:', JSON.stringify(resultSelect, null, 2));\n\n  // Note: The specific structure of `result` depends entirely on the library's implementation.\n  // Given its age, it might be a simple object or array of tokens/nodes.\n  // This example assumes a structure that might expose `statements` or similar.\n  if (resultSelect && Array.isArray(resultSelect.statements) && resultSelect.statements.length > 0) {\n    console.log('First statement type:', resultSelect.statements[0].type); // e.g., 'SELECT'\n  } else {\n    console.log('Could not determine statement type for SELECT.');\n  }\n\n  // Trying other statement types might fail or yield unexpected results\n  // as the README primarily focuses on SELECT queries.\n  // const resultInsert = parse(insertStatement);\n  // console.log('Parsed INSERT:', JSON.stringify(resultInsert, null, 2));\n\n} catch (error) {\n  console.error('SQL Parsing Error:', error.message);\n  console.warn('This package is very old and may not support modern or complex SQL syntax.');\n}","lang":"javascript","description":"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."},"warnings":[{"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`.","message":"The `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.","severity":"breaking","affected_versions":">=0.1.0"},{"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.","message":"This package is strictly CommonJS (`require`) and does not support ES Modules (`import/export`). Attempting to use `import` syntax will result in module resolution errors.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Change the import statement to `const { parse } = require('sql-parse');`.","cause":"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.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Ensure you are using CommonJS `require` syntax: `const { parse } = require('sql-parse');`. Verify that `sql-parse` is installed and the path is correct.","cause":"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.","error":"TypeError: (0, _sqlParse.parse) is not a function"},{"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.","cause":"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.","error":"Parse error at line X, column Y: Unexpected token Z"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}