TypeScript port of sqlglot, the SQL parser, transpiler, optimizer, and engine created by @tobymao.
All core ideas, architecture, and implementation logic belong to the original sqlglot project:
- Upstream project: https://github.com/tobymao/sqlglot
- Author: Toby Mao and contributors
This package is only a TypeScript translation of that work. We did not design the SQL engine, parser architecture, optimizer rules, or dialect behavior. The goal of this repository is to port the Python implementation as faithfully as possible.
@fduseless/sqlglot-ts provides a TypeScript build of sqlglot for JavaScript and TypeScript environments.
It includes:
- SQL parsing
- SQL generation
- Cross-dialect transpilation
- Expression tree utilities
- Optimizer and type annotation utilities
- A growing set of dialect-specific parser and generator behaviors
npm install @fduseless/sqlglot-tsimport { parseOne, transpile } from '@fduseless/sqlglot-ts';
const expression = parseOne('SELECT a + 1 FROM x');
console.log(expression.sql());
// SELECT a + 1 FROM x
console.log(expression.sql('spark'));
// SELECT a + 1 FROM x
console.log(
transpile('SELECT CAST(a AS SIGNED) FROM t', {
read: 'mysql',
write: 'postgres',
})[0],
);
// SELECT CAST(a AS BIGINT) FROM tThe public API is intended to closely follow the Python project where practical in TypeScript. Common entry points include:
parseparseOnetranspile- expression classes from
src/expressions - optimizer utilities such as
annotateTypes
This project is an active port, not an independent reimplementation. Behavior is continuously aligned against upstream Python sqlglot.
That means:
- some areas may still lag upstream
- names and behavior are chosen for parity first
- changes are often driven by upstream diff syncing rather than local redesign
If you need the canonical implementation, complete feature coverage, or want to understand the original design decisions, use or read the upstream Python project first:
https://github.com/tobymao/sqlglot
This repository is published under the MIT license. Please also review the license and notices of the upstream sqlglot project.