Registry / database / sql-parser-cst

sql-parser-cst

JSON →
library0.42.1jsnpmunverified

SQL Parser CST v0.42.1 is a JavaScript/TypeScript library that parses SQL into a Concrete Syntax Tree (CST), preserving all original formatting, comments, whitespace, and source location for round-trip parsing. Actively developed with stable tree structure, supports SQLite 3.45, BigQuery, and experimental MySQL, MariaDB, PostgreSQL, PL/pgSQL. Differentiates from AST parsers by enabling lossless code transformations without losing syntax details.

npm install sql-parser-cst
INSTALL
IMPORT
SIG · SQL-PARSER-CST
S
sql-parser-cst
databasejavascriptv0.42.1
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 'sql-parser-cst'
const parse = require('sql-parser-cst').parse
ESM-only package; CommonJS require not supported.
show
import { show } from 'sql-parser-cst'
import { show } from 'sql-parser-cst/show'
Direct subpath imports are not exposed; use top-level import.

Parses SQL to CST, transforms keywords to uppercase via visitor, and serializes back to SQL.

import { parse, show, cstVisitor } from 'sql-parser-cst'; const cst = parse('SELECT * FROM t', { dialect: 'sqlite' }); const toUpper = cstVisitor({ keyword: (kw) => { kw.text = kw.text.toUpperCase(); }, }); toUpper(cst); console.log(show(cst));
Debug
Known issues
breakingThe syntax tree structure is mostly stable but may change as new dialects are added.
fix
Lock dependency to minor version; upgrade only after testing.
affects: <1.0.0
deprecatedThe `parse()` `includeRange` option will be replaced by a positional data structure.
fix
Avoid relying on includeRange; plan migration.
affects: >=0.40.0 <0.43.0
gotchaParsing with unknown dialect throws error, not fallback.
fix
Always provide a valid dialect: 'sqlite', 'bigquery', 'mysql', etc.
affects: >=0.10.0
Errors
Common errors & fixes
Error: Unknown dialect 'postgres'. Supported dialects: sqlite, bigquery, mysql, mariadb, postgres, plpgsql
Typo in dialect name.
fix
Use 'postgres' or 'postgresql' (case-insensitive).
Upgrade
Version history
0.42.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
6
Meta
2
OpenAI (training)
1
Resources
sql-parser-cst — npm install sql-parser-cst · libregistry