Registry / database / dt-sql-parser

dt-sql-parser

JSON →
library4.5.0jsnpmunverified

A SQL parser library built with ANTLR4, supporting multiple SQL dialects including MySQL, PostgreSQL, Hive, Spark, Flink, Trino, and Impala. Version 4.5.0 is the latest stable release, with regular updates. It provides both parsing and code-completion functionality, distinguishing itself by targeting Big Data SQL dialects rather than standard SQL only. It is ESM-only since v4, requires Node >=18, and ships TypeScript type definitions.

npm install dt-sql-parser
INSTALL
IMPORT
SIG · DT-SQL-PARSER
D
dt-sql-parser
databasejavascriptv4.5.0
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.

MySQL
import { MySQL } from 'dt-sql-parser'
const MySQL = require('dt-sql-parser').MySQL
ESM-only since v4; default export is not available.
PostgreSQL
import { PostgreSQL } from 'dt-sql-parser'
import PostgreSQL from 'dt-sql-parser'
Named export, not default.
Hive
import { Hive } from 'dt-sql-parser'
import { HiveParser } from 'dt-sql-parser'
Class name is Hive, not HiveParser.
parse
import { MySQL } from 'dt-sql-parser'; const parser = new MySQL(); parser.parse('SELECT 1')
import { parse } from 'dt-sql-parser'
parse is a method on a parser instance, not a standalone export.
SqlParser class (generic)
import { MySQL } from 'dt-sql-parser'; new MySQL()
import { GenericSqlParser } from 'dt-sql-parser'
No generic parser; use specific dialect class.

Parses a SQL query and retrieves code completion suggestions using MySQL dialect.

import { MySQL } from 'dt-sql-parser'; const parser = new MySQL(); // Parse a SQL statement const result = parser.parse('SELECT * FROM table WHERE id = 1'); console.log(JSON.stringify(result, null, 2)); // Get code completion suggestions const suggestions = parser.getAllEntities('SELECT * FROM '); console.log(suggestions); // Use a different dialect import { PostgreSQL } from 'dt-sql-parser'; const pgParser = new PostgreSQL(); const pgResult = pgParser.parse('SELECT NOW()'); console.log(pgResult);
Debug
Known issues
breakingVersion 4.0+ is ESM-only and drops CommonJS support.
fix
Convert require() to import statements. Ensure package.json has 'type':'module' or use .mjs file extension.
affects: >=4.0.0
breakingNode.js < 18 is no longer supported in version 4.5.0.
fix
Upgrade Node.js to version 18 or higher.
affects: >=4.5.0
deprecatedThe getSQLParser and other helper functions from v3.x are removed.
fix
Use dialect-specific class constructors directly (e.g., new MySQL()).
affects: >=4.0.0
gotchaParse errors are thrown as exceptions; check try/catch for error handling.
fix
Wrap parse calls in try/catch blocks.
affects: >=4.0.0
gotchaThe getAllEntities method may return suggestions for incomplete queries; it does not always provide complete tables/columns.
fix
Validate suggestions against actual schema metadata if needed.
affects: >=4.0.0
gotchaTypeScript types are shipped but may be incomplete for all dialect APIs.
fix
Use strict mode and check type definitions; augment if needed.
affects: >=4.0.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Running package with require() in a CommonJS environment, but package is ESM-only.
fix
Use import syntax, add 'type':'module' in package.json, or rename file to .mjs.
TypeError: dt_sql_parser.default is not a constructor
Importing default export instead of named export.
fix
Use import { MySQL } from 'dt-sql-parser' instead of import Parser from 'dt-sql-parser'.
Error: The module 'dt-sql-parser' was resolved from 'file.js', but the 'exports' field does not export a valid subpath.
Using a path like 'dt-sql-parser/dist/...' or trying to import non-exported submodules.
fix
Only import from the main entry: './dt-sql-parser'.
Error: Unable to resolve antlr4 dependency
Missing runtime peer dependency antlr4.
fix
Install antlr4: npm install antlr4@^4.13.0
Upgrade
Version history
4.5.0latest on npm
Audit
Dependencies
antlr4requiredRuntime dependency for ANTLR4-generated parser and lexer classes
Agent activity
5 hits · last 30 days
node
4
Resources