Registry / database / node-sql-parser-benberi

node-sql-parser-benberi

JSON →
library5.3.27jsnpmunverified

A SQL parser for Node.js that converts SQL statements into an abstract syntax tree (AST) and back. Version 5.3.27 supports multiple dialects including MySQL, PostgreSQL, SQLite, BigQuery, and others. It outputs visited table and column lists with authority information. Released monthly, it supports SELECT, INSERT, UPDATE, DELETE, DROP, TRUNCATE, and RENAME commands. Differentiators: provides both AST and table/column lists, supports multiple databases, and is available as a UMD bundle for browsers. Ships TypeScript types.

npm install node-sql-parser-benberi
INSTALL
IMPORT
SIG · NODE-SQL-PARSER-BE
N
node-sql-parser-benberi
databasejavascriptv5.3.27
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.

Parser
import { Parser } from 'node-sql-parser'
import Parser from 'node-sql-parser'
Default export does not exist; use named import.
astify
const parser = new Parser(); const ast = parser.astify('SELECT * FROM t')
const ast = astify('SELECT * FROM t')
astify is a method on Parser instance, not a standalone function.
sqlify
const sql = parser.sqlify(ast)
const sql = sqlify(ast)
sqlify is also a method on Parser instance.

Parses a SQL SELECT statement into an AST, retrieves table and column lists, and converts AST back to SQL.

import { Parser } from 'node-sql-parser'; const parser = new Parser(); const sql = 'SELECT id, name FROM students WHERE age < 18'; const ast = parser.astify(sql); console.log(ast); const { tableList, columnList, ast: astResult } = parser.parse(sql); console.log(tableList, columnList); const backToSql = parser.sqlify(ast); console.log(backToSql);
Debug
Known issues
breakingIn v4.0.0, the library changed from CommonJS to ESM-only. The Parser constructor is no longer the default export, and require('node-sql-parser') no longer works.
fix
Use dynamic import: const { Parser } = await import('node-sql-parser'); or set type:'module' in package.json.
affects: >=4.0.0
deprecatedThe method 'parse' returns an object with 'ast' property, but 'astify' is preferred since v3. 'parse' still exists for backward compatibility but may be removed in the future.
fix
Use 'parser.astify(sql)' instead of 'parser.parse(sql).ast'.
affects: >=3.0.0 <4.0.0
gotchaWhen using with TypeScript, you must install @types/node-sql-parser if using version <5.0.0, but since v5.0.0 types are shipped with the package.
fix
Upgrade to v5+ to avoid external type dependency.
affects: >=5.0.0
gotchaThe library does not support all SQL dialects equally; some features may be missing for less common databases like Snowflake (alpha).
fix
Check supported dialect list; for unsupported syntax, consider using raw string manipulation.
affects: >=5.0.0
deprecatedDatabase dialect names changed in v5: 'mysql' is now 'mysql', 'postgresql' is now 'postgresql'. The old aliases like 'postgres' no longer work.
fix
Use the exact dialect string as documented: 'mysql', 'postgresql', 'sqlite', etc.
affects: >=5.0.0
Errors
Common errors & fixes
TypeError: (intermediate value).astify is not a function
Importing the default export instead of named export Parser.
fix
Use: import { Parser } from 'node-sql-parser'; const parser = new Parser();
Cannot find module 'node-sql-parser'
Missing installation or using npm's scoped package name incorrectly.
fix
Run: npm install node-sql-parser. Do not use @taozhi8833998/node-sql-parser for npm registry.
SyntaxError: Unexpected token (at column X) - for subqueries
Subqueries with correlated references may not be parsed correctly in older versions.
fix
Update to v5.3+ or wrap subquery in parentheses properly.
Upgrade
Version history
5.3.27latest on npm
Audit
Dependencies
big-integerrequiredUsed for handling large integers in AST
Agent activity
4 hits · last 30 days
node
4
Resources
node-sql-parser-benberi — npm install node-sql-parser-benberi · libregistry