Registry / database / lite-ui-sql-parser

lite-ui-sql-parser

JSON →
library1.8.31jsnpmunverified

A SQL parser for Node.js that converts SQL statements into an abstract syntax tree (AST) and back. Version 1.8.31 supports SELECT, DELETE, UPDATE, INSERT, DROP, TRUNCATE, and RENAME commands. It can handle multiple SQL statements separated by semicolons and outputs tables and columns visited. Supports MySQL, PostgreSQL, Hive, MariaDB, and TransactSQL dialects. Ships with TypeScript definitions. The parser is designed for simple SQL parsing needs and allows opting into TypeScript types via definitely typed.

npm install lite-ui-sql-parser
INSTALL
IMPORT
SIG · LITE-UI-SQL-PARSER
L
lite-ui-sql-parser
databasejavascriptv1.8.31
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'
const Parser = require('node-sql-parser').Parser
ESM and CJS both work. The package exports a Parser class.
NodeSQLParser
import NodeSQLParser from 'node-sql-parser'
const NodeSQLParser = require('node-sql-parser')
Default import provides the NodeSQLParser namespace (includes Parser, AST types). Prefer named import for Parser.
Parser (CJS)
const { Parser } = require('node-sql-parser')
const parser = require('node-sql-parser')
CommonJS destructuring is required to get the Parser class. The default export is not the Parser constructor.

Parses a SQL SELECT statement into an AST, then converts it back to SQL string.

const { Parser } = require('node-sql-parser'); const parser = new Parser(); const ast = parser.astify("SELECT id, name FROM students WHERE age > 18"); console.log(JSON.stringify(ast, null, 2)); // Convert AST back to SQL const sql = parser.sqlify(ast); console.log(sql);
Debug
Known issues
gotchaThe parser does not support all SQL syntax. Complex queries (e.g., window functions, CTEs, or advanced joins) may produce incorrect AST or fail.
fix
Check the supported features list. For unsupported syntax, consider using a more full-featured parser like sql.js or a database-specific parser.
affects: <=1.8.31
breakingVersion 1.0.0 introduced a completely rewritten API. The old version used a different export and method signatures.
fix
Update imports and method calls according to the new API: `const { Parser } = require('node-sql-parser')` and use `astify`/`sqlify`.
affects: >=1.0.0
gotchaThe AST structure is not fully documented. Fields may differ between dialects or versions.
fix
Inspect the AST by console logging it. File an issue if you need specific fields.
affects: all
deprecatedThe `parse` method is deprecated in favor of `astify`.
fix
Replace `parser.parse(sql)` with `parser.astify(sql)`.
affects: >=1.4.0
gotchaWhen using MySQL, the parser may not handle backtick-quoted identifiers correctly in some edge cases.
fix
Test with your specific queries. If needed, preprocess the SQL to remove backticks.
affects: all
Errors
Common errors & fixes
Cannot find module 'node-sql-parser'
Package not installed or wrong import path.
fix
Run `npm install node-sql-parser` and ensure the import is correct: `{ Parser } from 'node-sql-parser'`.
TypeError: parser.astify is not a function
Using an outdated version or incorrect import (default import instead of destructuring Parser).
fix
Update to latest version: `npm install node-sql-parser@latest`. Use `const { Parser } = require('node-sql-parser')`.
SQL parsing error: unexpected token
The SQL syntax is not supported by the parser (e.g., window functions, complex expressions).
fix
Simplify the query or use a different SQL parser that supports the feature.
Cannot read properties of undefined (reading 'table')
Astify returned an empty or malformed AST, likely due to unsupported syntax.
fix
Check the SQL for unsupported constructs. Use a try-catch around astify.
Upgrade
Version history
1.8.31latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
lite-ui-sql-parser — npm install lite-ui-sql-parser · libregistry