{"id":26427,"library":"sqlglot-ts","title":"sqlglot-ts","description":"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.","status":"active","version":"0.1.5","language":"javascript","source_language":"en","source_url":"https://github.com/Flamefork/sqlglot-ts","tags":["javascript","sql","parser","transpiler","ast","duckdb"],"install":[{"cmd":"npm install sqlglot-ts","lang":"bash","label":"npm"},{"cmd":"yarn add sqlglot-ts","lang":"bash","label":"yarn"},{"cmd":"pnpm add sqlglot-ts","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only; CommonJS require() fails in Node < 22 or without experimental VM modules.","wrong":"const { parseOne } = require('sqlglot-ts')","symbol":"parseOne","correct":"import { parseOne } from 'sqlglot-ts'"},{"note":"Dialects must be imported as side effects before calling transpileOne; otherwise the default standard SQL dialect is used, leading to unexpected results.","wrong":"import { transpileOne } from 'sqlglot-ts'; transpileOne(sql, { read: 'duckdb', write: 'postgres' })","symbol":"transpileOne","correct":"import { transpileOne } from 'sqlglot-ts'; import 'sqlglot-ts/dialects/duckdb'; import 'sqlglot-ts/dialects/postgres'"},{"note":"Dialect classes are exported from 'sqlglot-ts/dialects', not the main package. Importing from 'sqlglot-ts' only yields core functions.","wrong":"import { DuckDB } from 'sqlglot-ts'","symbol":"DuckDB","correct":"import { DuckDB } from 'sqlglot-ts/dialects'"},{"note":"Expression types and classes are under 'sqlglot-ts/expressions'; re-exports from main package are not available.","wrong":"import { Column } from 'sqlglot-ts'","symbol":"exp","correct":"import * as exp from 'sqlglot-ts/expressions'"}],"quickstart":{"code":"import { parseOne, transpileOne } from 'sqlglot-ts';\nimport 'sqlglot-ts/dialects/duckdb';\nimport 'sqlglot-ts/dialects/postgres';\nconst ast = parseOne('SELECT TRY_CAST(x AS INT)');\nconsole.log(ast.sql());\nconst result = transpileOne('SELECT TRY_CAST(x AS INT)', { read: 'duckdb', write: 'postgres' });\nconsole.log(result);","lang":"typescript","description":"Parses a DuckDB-specific SQL statement and transpiles it to PostgreSQL, demonstrating dialect imports and transpilation."},"warnings":[{"fix":"Add import 'sqlglot-ts/dialects/your-dialect' at top of file before usage.","message":"Dialect side-effect imports must precede any parsing/transpilation calls.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Check ast.errors after parsing to detect syntax errors.","message":"parseOne() does not throw on invalid SQL; returns a partial AST with errors attached.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use import { DuckDB } from 'sqlglot-ts/dialects' when you need the class; retain side-effect imports for registration.","message":"Direct import of dialect classes from 'sqlglot-ts/dialects' is preferred over 'sqlglot-ts/dialects/duckdb' side-effect imports for type access.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Use transpileOne for single statement input; for multi-statement SQL, use transpile() and handle the array.","message":"transpileOne() returns a string; transpile() returns an array of strings. Mixing them up causes type errors.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Upgrade to Node.js 18 or later.","message":"Node.js >=18 required; engine restriction enforced.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Configure your bundler (e.g., Vite: module.rules) to treat 'sqlglot-ts/dialects/*' as side-effectful.","message":"Browser bundlers may tree-shake dialect registrations if imports are not recognized as side effects.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.1.5':24 '20':72 '40kb':73 '500':39 '80kb':69 'allow':58 'altern':77 'ast':96,102 'base':85 'bigqueri':47 'browser':15 'browser-first':14 'bundl':65 'case':41 'core':68 'coverag':52 'current':22 'depend':21 'design':17 'dialect':30,45,63,75,93 'differenti':54 'duckdb':29,103 'e.g':78 'earli':27 'emphas':90 'esm':56 'etc':49 'first':16 'full':95 'gzip':70 'includ':44 'javascript':98 'keep':64 'modul':57 'moo':84 'moo-bas':83 'node':80 'node-sql-pars':79 'parser':10,82,86,100 'partial':51 'per':62,74 'plus':71 'port':5 'postgresql':46 'python':35 'releas':28 'runtim':20 'shake':61 'size':66 'small':67 'snowflak':48 'sql':9,81,99 'sqlglot':2,7,36,88 'sqlglot-t':1,87 'suit':38 'test':33,40 'thorough':32 'transpil':12,91,101 'travers':97 'tree':60 'tree-shak':59 'ts':3,89 'typescript':4 'unbundl':55 'uniqu':53 'unlik':76 'version':23 'zero':19","created_at":"2026-05-01T13:49:55.205818+00:00","updated_at":"2026-05-01T13:49:55.205818+00:00","problems":[{"fix":"Ensure tsconfig.json includes 'moduleResolution': 'node16' or 'nodenext' and 'allowImportingTsExtensions': false.","cause":"Missing or misconfigured TypeScript module resolution; deep imports may not be recognized.","error":"Cannot find module 'sqlglot-ts/dialects/duckdb' or its corresponding type declarations."},{"fix":"Add import 'sqlglot-ts/dialects/duckdb' at the top of your file before any sqlglot-ts usage.","cause":"Dialect side-effect import missing before calling parse/transpile functions.","error":"Error: Dialect 'duckdb' not registered. Did you import a dialect module?"},{"fix":"Check ast.errors after parseOne() to validate; handle invalid SQL gracefully.","cause":"ast is not a proper Expression object; likely parseOne() returned an error object due to invalid SQL.","error":"TypeError: ast.walk is not a function"},{"fix":"Import the dialect class: import { Postgres } from 'sqlglot-ts/dialects' then use Postgres.generate(ast).","cause":"Dialect class not imported or incorrectly imported. generate is a static method on dialect classes.","error":"Cannot read properties of undefined (reading 'generate')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/Flamefork/sqlglot-ts","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/sqlglot-ts","openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-05-01","next_check":"2026-07-30","install_tag":null}}