npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sqlglot-ts

v0.1.2

Published

SQL parser and transpiler for TypeScript - port of SQLGlot

Readme

sqlglot-ts

TypeScript port of SQLGlot — a SQL parser and transpiler.

Browser-first implementation focusing on parsing and transpilation. Zero runtime dependencies.

Early release. DuckDB dialect is fully tested against Python SQLGlot's test suite (500+ test cases). Other dialects are included and functional but have varying levels of coverage — expect gaps in edge cases. Contributions and bug reports welcome.

Installation

npm install sqlglot-ts

Usage

Parse SQL

import { parse, parseOne } from 'sqlglot-ts';

// Parse multiple statements
const statements = parse('SELECT 1; SELECT 2');

// Parse a single statement
const ast = parseOne('SELECT * FROM users WHERE id = 1');

Transpile between dialects

import { transpileOne } from 'sqlglot-ts';
import 'sqlglot-ts/dialects/duckdb';
import 'sqlglot-ts/dialects/postgres';

const sql = transpileOne(
  'SELECT TRY_CAST(x AS INT)',
  { read: 'duckdb', write: 'postgres' }
);
// => 'SELECT CAST(x AS INT)'

Use dialect objects

import { parseOne } from 'sqlglot-ts';
import { Postgres, BigQuery, DuckDB } from 'sqlglot-ts/dialects';

const ast = parseOne('SELECT TRY_CAST(x AS INT)');

console.log(BigQuery.generate(ast));
console.log(Postgres.generate(ast));
console.log(DuckDB.generate(ast));

Work with the AST

import { parseOne } from 'sqlglot-ts';
import * as exp from 'sqlglot-ts/expressions';

const ast = parseOne('SELECT a, b FROM t WHERE x > 1');

// Traverse the AST
for (const node of ast.walk()) {
  console.log(node.key);
}

// Find specific node types
const columns = ast.findAll(exp.Column);
columns.forEach(col => console.log(col.name));

// Generate SQL back
console.log(ast.sql());

Dialect imports

The core sqlglot-ts entry point does not load any dialect — only standard SQL parsing works out of the box. Import the dialects you need:

// Only what you need (recommended)
import 'sqlglot-ts/dialects/duckdb';
import 'sqlglot-ts/dialects/postgres';

// Or all dialects at once
import 'sqlglot-ts/dialects';

Each dialect file registers itself on import via Dialect.register().

Supported Dialects

Fully tested: DuckDB

Included (partial coverage): Athena, BigQuery, ClickHouse, Databricks, Doris, Dremio, Drill, Druid, Dune, Exasol, Fabric, Hive, Materialize, MySQL, Oracle, PostgreSQL, Presto, PRQL, Redshift, RisingWave, SingleStore, Snowflake, Solr, Spark, SQLite, StarRocks, Tableau, Teradata, Trino, T-SQL.

API Reference

Functions

  • parse(sql, options?) — Parse SQL into AST array
  • parseOne(sql, options?) — Parse a single SQL statement
  • transpile(sql, options?) — Transpile SQL between dialects (returns array)
  • transpileOne(sql, options?) — Transpile a single SQL statement

Classes

  • Dialect — Base dialect class with registry
  • Parser — SQL parser
  • Generator — SQL generator
  • Tokenizer — SQL tokenizer
  • Expression — Base AST node class

Bundle Size

The library uses unbundled ESM — each dialect is a separate file. Core parsing (sqlglot-ts) without any dialects is the smallest import. Adding dialects increases the total proportionally.

Typical sizes (gzipped):

  • Core only: ~80KB
  • Core + one dialect: ~100–120KB
  • All dialects: ~150KB

Examples

Runnable examples that double as tests live in examples/ — they import from sqlglot-ts just like user code and cover the full public API: parsing, transpilation, dialects, AST traversal, builder, and serialization.

npm run test:examples  # Run all examples

Development

npm install            # Install dependencies
npm run build          # Build
npm test               # format:check + lint + typecheck + examples + compat DuckDB
npm run test:compat    # Full compat run (all dialects)
npm run test:packaging # npm pack → temp install → verify exports
npm run fix            # Format + lint fix
npm run generate       # Generate TS expressions from Python SQLGlot
npm run release -- 0.2.0  # Bump version, commit, tag, push → CI publishes to npm

Differences from Python SQLGlot

Included:

  • Tokenizer, Parser, Generator
  • All 31 dialects
  • Expression AST classes
  • Cross-dialect transpilation

Not included:

  • Optimizer (qualify, annotate_types, simplify, etc.)
  • Executor
  • Lineage analysis
  • Schema module

License

MIT