Registry / database / node-sqlparser

node-sqlparser

JSON →
library1.0.4jsnpmunverified

A SQL parser for Node.js that generates an AST from SQL statements and can stringify AST back to SQL. Current version 1.0.4 is the latest stable release, with no active development since 2016. Written in pure JavaScript, it uses PEG.js for parsing and supports SQL syntax inspired by various databases like MySQL, PostgreSQL, BigQuery, and PL/SQL. Compared to alternatives like node-sql-parser (with ongoing support), this package is minimal and was historically used by Alibaba's nQuery project. No TypeScript types or ES module support; requires Node >=0.8.0.

npm install node-sqlparser
INSTALL
IMPORT
SIG · NODE-SQLPARSER
N
node-sqlparser
databasejavascriptv1.0.4
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.

parse
import { parse } from 'node-sqlparser'
const parse = require('node-sqlparser').parse
The package is ESM-compatible if using ES modules; however, the original documentation shows CommonJS usage. Both work.
stringify
import { stringify } from 'node-sqlparser'
const stringify = require('node-sqlparser').stringify
Same as parse; both are named exports from the module.
AST
import { AST } from 'node-sqlparser'
const AST = require('node-sqlparser').AST
AST is a constructor function that can be instantiated with 'new'.
default export
import sqlparser from 'node-sqlparser'
const sqlparser = require('node-sqlparser')
Default export is not documented; the package likely does not have a default export. Prefer named imports.

Parses a SQL query into an AST and then stringifies it back to SQL. Demonstrates the two main static functions.

import { parse, stringify } from 'node-sqlparser'; const sql = 'SELECT * FROM users WHERE age > 18'; const ast = parse(sql); console.log(JSON.stringify(ast, null, 2)); const reconstructed = stringify(ast); console.log(reconstructed); // Expected output: SQL string similar to input
Debug
Known issues
breakingNo active maintenance since 2016. Security vulnerabilities or compatibility issues may exist.
fix
Consider migrating to actively maintained alternatives such as node-sql-parser (npm: node-sql-parser) or @babel/parser for SQL.
affects: >=0.0.0
deprecatedPackage is abandoned; no updates for over 8 years.
fix
Switch to an alternative library. Node compatibility may break in future Node releases.
affects: >=1.0.0
gotchaThe parser may not support modern SQL syntax (CTEs, window functions, etc.) or complex joins. Test your specific SQL patterns.
fix
If you need advanced SQL parsing, use a more comprehensive parser like node-sql-parser or antlr4-based parsers.
affects: >=1.0.0
gotchaNo TypeScript type declarations are provided; you must write your own or use @ts-ignore.
fix
Use a community-provided types package if available, or avoid TypeScript with this library.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'node-sqlparser'
Package not installed or not in node_modules.
fix
Run 'npm install node-sqlparser' to install.
TypeError: parse is not a function
Importing incorrectly; parse is a named export.
fix
Use 'import { parse } from 'node-sqlparser'' or 'const { parse } = require('node-sqlparser')'.
SyntaxError: Unexpected token (your SQL)
SQL syntax not supported by the parser.
fix
Simplify your SQL or use a different parser that supports your dialect. Check the parser's grammar.
ReferenceError: AST is not defined
Trying to use the AST constructor without importing it correctly.
fix
Use 'import { AST } from 'node-sqlparser'' or 'const { AST } = require('node-sqlparser')'.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
node-sqlparser — npm install node-sqlparser · libregistry