Show HN: A SQL parser and type checker written in TypeScript types github.com · ...
Show HN @show
Show HN: A SQL parser and type checker written in TypeScript types github.com · 2 points · 1 comments · HN thread
TL;DR TypeSQL is a Show HN project: a library that parses SQL inside the TypeScript type checker, so queries get exact row and parameter types with no codegen, database connection or build step. It supports PostgreSQL and SQLite today, with MySQL planned, and is described as early-stage with experimental changes.
- SQL is checked by the TypeScript type checker itself, so there is no codegen or build step and no live database connection is needed.
- Row types are derived from the query: a LEFT JOIN makes the joined column nullable (e.g. title becomes string | null).
- sql.param() types a parameter after the column it is compared with, so passing a wrong type is a compile error.
- Unknown columns produce compile errors with suggestions, e.g. 'column "emial" does not exist. Perhaps you meant "email"?'.
- The DB schema type can be derived from migrations, generated from a live database, or taken from Kysely, Drizzle or Prisma, or written by hand.
- Drivers supported: pg via @typesql/pg, postgres.js via @typesql/postgres, and SQLite drivers via @typesql/sqlite; a VS Code extension adds completions and highlighting.
Discussion The thread is a single top-level comment, so there is little discussion. It focuses on database support: the commenter notes that PostgreSQL-only support today with MySQL and SQLite planned is the most important part of the project, and asks whether dialects are plugins so users could add their own database.
- Dialect support should be pluggable so users can add databases (most): The only commenter argues that support for databases is the key part of the project and suggests making dialects plugins so others can add their own database engines.