Registry / database / bq-dt-sql-parser

bq-dt-sql-parser

JSON →
library4.1.0jsnpmunverified

dt-sql-parser is a SQL parser library built with ANTLR4, targeting BigData SQL dialects including MySQL, Flink, Spark (with recursive query support), Hive, PostgreSQL, Trino, and Impala. Version 4.1.0 (latest stable) provides syntax validation, code completion, lexical parsing, AST traversal, and table/column extraction. It is actively maintained with frequent releases. Key differentiators: supports multiple BigData dialects in one library, TypeScript-native with full type definitions, and offers advanced features like recursive query parsing for SparkSQL. Requires Node >=18 and is ESM-only.

npm install bq-dt-sql-parser
INSTALL
IMPORT
SIG · BQ-DT-SQL-PARSER
B
bq-dt-sql-parser
databasejavascriptv4.1.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; CommonJS require() is not supported.
SparkSQL
import { SparkSQL } from 'dt-sql-parser'
import SparkSQL from 'dt-sql-parser'
Named export, not default. Also supports HiveSQL, FlinkSQL, PostgreSQL, TrinoSQL, ImpalaSQL.
AstListener
import { AstListener } from 'dt-sql-parser'
import { Listener } from 'dt-sql-parser'
For AST traversal; class names are prefixed with 'Ast'. Also available: AstVisitor.

Shows basic validation, code completion, and table extraction with MySQL parser. Replace MySQL with any other dialect class.

import { MySQL } from 'dt-sql-parser'; const mysql = new MySQL(); const sql = 'SELECT id, name FROM users WHERE age > 18'; const errors = mysql.validate(sql); if (errors.length === 0) { console.log('Valid SQL'); } else { console.error('Validation errors:', errors); } // Code completion example (requires a parse context) const caretPosition = { line: 1, column: 25 }; // after 'FROM' const suggestions = mysql.getAllCandidates(sql, caretPosition); console.log('Suggestions:', suggestions); extractTableAndColumn example: const tables = mysql.getTables(sql); console.log('Tables:', tables);
Debug
Known issues
breakingESM-only import: This package is ESM-only starting from v4. Using require() will fail with ERR_REQUIRE_ESM.
fix
Use import syntax or dynamic import().
affects: >=4.0.0
gotchaNode Version Requirement: The package requires Node >=18. Versions below will not work.
fix
Upgrade Node to v18 or later.
affects: >=4.0.0
gotchaParser instantiation: Each dialect parser must be instantiated separately. Shared state between instances can cause unexpected behavior.
fix
Create a new instance per dialect or per use case (e.g., const mysql = new MySQL(); const spark = new SparkSQL();).
affects: >=1.0.0
gotchaCase sensitivity: SQL keywords and identifiers may be case-insensitive depending on dialect, but parser expects uppercase keywords in validate method.
fix
Always provide SQL with uppercase keywords or ensure consistent casing.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Named export 'MySQL' not found. The requested module 'dt-sql-parser' is a CommonJS module, which may not support all module.exports as named exports.
Using require() with destructuring in a CommonJS context, but package is ESM-only.
fix
Use import { MySQL } from 'dt-sql-parser' or use dynamic import().
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/dt-sql-parser/build/index.js from /path/to/app.js not supported.
Direct require() of an ESM package.
fix
Convert your project to ESM or use dynamic import().
TypeError: mysql.validate is not a function
The MySQL instance was not created correctly, possibly due to using default import instead of named.
fix
Ensure you use: import { MySQL } from 'dt-sql-parser'; then const mysql = new MySQL();
SyntaxError: Unexpected token 'export'
Running in an environment that doesn't support ES modules (e.g., older Node).
fix
Upgrade Node to >=18 or use a bundler like webpack/rollup.
Upgrade
Version history
4.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
14
Bingbot
1
OpenAI (training)
1
Resources
bq-dt-sql-parser — npm install bq-dt-sql-parser · libregistry