SQL parser for JavaScript and TypeScript, powered by datafusion-sqlparser-rs via WebAssembly.
- [2026/02] sqlparser-ts has been officially integrated into Apache Airflow
- [2026/01] Officially released sqlparser-ts 🎉
- Parse SQL into a detailed AST with full TypeScript types
- Support 16 SQL dialects (PostgreSQL, MySQL, SQLite, BigQuery, and more)
- Run in Node.js and browsers
- Stay small (~600KB gzipped) and fast (Rust + WebAssembly)
- Ship zero native dependencies
npm install @guanmingchiu/sqlparser-tsimport{init,parse,format,validate}from'@guanmingchiu/sqlparser-ts';// Initialize WASM module (must be called once before using any parser functions)awaitinit();// Parse SQL into ASTconstast=parse('SELECT * FROM users');// With specific dialectconstast=parse('SELECT * FROM users WHERE id = $1','postgresql');// Format SQLconstsql=format('select * from users');// "SELECT * FROM users"// Validate SQL (throws on invalid)validate('SELECT * FROM users');// okWASM packages must be excluded from Vite's dev server dependency pre-bundling. This only affects the dev server. Production builds use Rollup instead of esbuild and handle WASM files correctly.
// vite.config.tsexportdefaultdefineConfig({optimizeDeps: {exclude: ['@guanmingchiu/sqlparser-ts'],},});// Parse and inspectconstast=parse('SELECT id, name FROM users WHERE active = true');console.log(JSON.stringify(ast,null,2));// Multiple statementsconststatements=parse(` SELECT * FROM users; SELECT * FROM orders;`);console.log(statements.length);// 2// Modify AST and convert back to SQLconstast=parse('SELECT * FROM users')[0];// ... modify ast ...constsql=format(JSON.stringify([ast]));try{parse('SELEC * FORM users');}catch(e){console.error(e.message);// Parse error details}generic, ansi, mysql, postgresql, sqlite, snowflake, redshift, mssql, clickhouse, bigquery, duckdb, databricks, hive, oracle, spark, teradata
Follows Semantic Versioning with upstream tracking:
- MAJOR.MINOR: Tracks upstream datafusion-sqlparser-rs
- PATCH: sqlparser-ts specific releases
Example: 0.60.4 = upstream 0.60 + 4 sqlparser-ts releases
Apache-2.0