Registry / database / js-sql-parse

js-sql-parse

JSON →
library0.2.9jsnpmunverified

A nearley-based SQL parser and analyzer for JavaScript. Current version 0.2.9 is in early development (work in progress) with support for SELECT and CREATE VIEW operations. Outputs structured analysis including referenced tables, created tables, source tables from subqueries/joins, and the parse tree. Differentiators: lightweight, no external database required, focuses on SQL analysis rather than execution. Release cadence: irregular maintenance updates.

npm install js-sql-parse
INSTALL
IMPORT
SIG · JS-SQL-PARSE
J
js-sql-parse
databasejavascriptv0.2.9
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.

default (parser)
import parser from 'js-sql-parse'
const { parse } = require('js-sql-parse')
Default export is the parse function. Named import 'parse' is incorrect; use default import or require.
default (parser)
const parser = require('js-sql-parse')
const { parse } = require('js-sql-parse')
CommonJS: require returns the default export directly, not an object with 'parse'.
TypeScript types
import parser from 'js-sql-parse'
No official TypeScript types. Use `@types/js-sql-parse` or define your own.

Parses a SQL SELECT query with a JOIN and logs the analyzed properties: operation, referenced tables, source tables, and joins.

import parser from 'js-sql-parse'; const query = 'SELECT a.name, b.order_date FROM customers a JOIN orders b ON a.id = b.customer_id WHERE a.active = 1'; const result = parser.parse(query); console.log('Operation:', result.operation); console.log('Referenced Tables:', result.referencedTables); console.log('Source Tables:', result.sourceTables); console.log('Joins:', result.joins);
Debug
Known issues
gotchaOnly SELECT and CREATE VIEW operations are supported. Other SQL statements (INSERT, UPDATE, DELETE, etc.) will not parse correctly or may throw.
fix
Check the operation field after parsing. For unsupported operations, consider a different SQL parser.
affects: all
deprecatedThe package is a work in progress and API may change without notice. Versions below 1.0.0 are considered unstable.
fix
Pin to a specific version and test thoroughly before upgrading.
affects: <1.0.0
gotchaThe parse result's `sourceTables` may include tables from subqueries and joins, but the exact behavior is not well-documented. Test with complex queries.
fix
Inspect the `parsed` field (the Nearley parse tree) for full details.
affects: all
Errors
Common errors & fixes
TypeError: parser.parse is not a function
Using named import { parse } instead of default import.
fix
Use `import parser from 'js-sql-parse'` or `const parser = require('js-sql-parse')`.
SyntaxError: Unexpected token at position X
SQL query contains unsupported syntax or dialect-specific features (e.g., MySQL backticks, PostgreSQL ILIKE).
fix
Simplify the query to standard SQL; avoid dialect-specific keywords and operators.
Upgrade
Version history
0.2.9latest on npm
Audit
Dependencies
nearleyrequiredGrammar parser engine for SQL syntax
Agent activity
4 hits · last 30 days
node
4
Resources
js-sql-parse — npm install js-sql-parse · libregistry