TypeScript port of SQLGlot — a SQL parser and transpiler with browser-first design and zero runtime dependencies. Current version 0.1.5 is an early release; DuckDB dialect is thoroughly tested against Python SQLGlot's suite (500+ test cases), while other included dialects (PostgreSQL, BigQuery, Snowflake, etc.) have partial coverage. Unique differentiator: unbundled ESM modules allow tree-shaking per dialect, keeping bundle sizes small (core ~80KB gzipped, plus ~20–40KB per dialect). Unlike alternatives (e.g., node-sql-parser, moo-based parsers), sqlglot-ts emphasizes transpilation between dialects and full AST traversal.
npm install sqlglot-tsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Parses a DuckDB-specific SQL statement and transpiles it to PostgreSQL, demonstrating dialect imports and transpilation.
Add import 'sqlglot-ts/dialects/your-dialect' at top of file before usage.
Check ast.errors after parsing to detect syntax errors.
Use import { DuckDB } from 'sqlglot-ts/dialects' when you need the class; retain side-effect imports for registration.Use transpileOne for single statement input; for multi-statement SQL, use transpile() and handle the array.
Upgrade to Node.js 18 or later.
Configure your bundler (e.g., Vite: module.rules) to treat 'sqlglot-ts/dialects/*' as side-effectful.
Ensure tsconfig.json includes 'moduleResolution': 'node16' or 'nodenext' and 'allowImportingTsExtensions': false.
Add import 'sqlglot-ts/dialects/duckdb' at the top of your file before any sqlglot-ts usage.
Check ast.errors after parseOne() to validate; handle invalid SQL gracefully.
Import the dialect class: import { Postgres } from 'sqlglot-ts/dialects' then use Postgres.generate(ast).No dependency data recorded yet.