Skip to content

hyper-sqlTyped SQL for TypeScript

Write real SQL in plain .sql files. Get database-verified types, instant tsc checks, and zero query-builder overhead—for SQLite and Postgres.

How it works

Only hyper-sql pull talks to a database. Builds, CI, and your editor read only your .sql files and the committed sql.lock.

How hyper-sql works: Pull, Build, and RunThree-stage pipeline: hyper-sql pull inspects schema.sql and queries against a scratch database to write sql.lock; tsc runs the content mapper offline using .sql files and sql.lock to produce typed modules; your app executes cached prepared statements with runtime row validation.1Pullhyper-sql pullschema.sqlsrc/*.sqlScratch SQLite or PostgresPrepares queries without running themsql.lock (committed)Only step that touches a database2Buildtscsrc/*.sqlsql.lockTS 7.1 Content MapperChecks SQL + emits flat TS typesTyped .sql modulesOffline · fast tsc · CI-ready3RunNode / HyperTSmain.tsyour driverPrepared SQL + Array DecodeValidates every cell against sql.lockTyped, verified rowsZero query-builder overhead
Pull once when your SQL or schema changes; build offline anywhere; run directly on your own database driver.

From plain SQL to a typed module

Import a .sql file just like a .ts module. TypeScript's content mapper generates flat, concrete interfaces so tsc and IDE autocomplete stay fast even on large schemas.

How a .sql file becomes a typed TypeScript modulesrc/book-by-isbn.sql combined with sql.lock through hyper-sql's content mapper generates the function bookByIsbn plus flat BookByIsbnParams and BookByIsbnRow interfaces.src/book-by-isbn.sql-- @oneSELECT isbn, title, price_centsFROM booksWHERE isbn = :isbn@one → Row | undefined:isbn → ParamsSELECT → Rowhyper-sqlcontent mapper+ sql.lockImported TypeScript module (virtual)export interface BookByIsbnParams {isbn: string}export interface BookByIsbnRow {isbn: string; title: string;price_cents: number}export function bookByIsbn(db, p): BookByIsbnRow | undefined
Every column, parameter, and nullability rule maps straight to plain TypeScript types—no complex generic query-builder inference.

Why hyper-sql?

The ergonomics of typed database access without giving up real SQL or paying ORM and query-builder overhead.

Real SQL, fewer round-trips

Use the full power of SQLite and Postgres—nested json_agg / json_group_array rows, bulk unnest inserts, MERGE, and CTEs—so you fetch or write graphs in one query instead of N+1 ORM calls.

Zero query-builder runtime tax

Static queries compile to constant pre-numbered SQL strings, dynamic variants are cached once, SQLite caches prepared statements, and rows decode from positional arrays straight into fixed-shape objects.

Fast tsc & snappy autocomplete

Because types are resolved by the database and emitted as flat Params and Row interfaces, TypeScript doesn't grind through deeply nested conditional types on every keystroke.

Compile-time + runtime proof

Types aren't wishful casts: every cell is validated against sql.lock at runtime (catching unsafe integers beyond ±2⁵³, unexpected NULLs, and JSON drift), and Postgres transactions guard against common misuse.

Bring your own driver

Zero production dependencies and no bundled driver—pass your existing node:sqlite, pg.Client, or custom client. Runs on Node 24+, in the browser playground, and natively via HyperTS.

Deterministic, offline CI

Commit sql.lock alongside your queries. Build machines never need a running database, and hyper-sql pull --check fails CI if someone forgets to re-pull after editing SQL.

Built-in AI agent skill

Using Claude Code, Antigravity, or another coding agent? The package ships a ready-to-link agent skill with the full workflow, annotation and dynamic-SQL references, error catalog, and runnable examples.