ismailkarsli
4 hours ago
Hi HN, TypeSQL parses Postgres SQL string literals inside TypeScript's type system, so you get the exact row and parameter types with no codegen and no database connection. A misspelled column is a compile error.
const q = sql("SELECT id, email FROM users WHERE id = $1", 7);
// Query<{ id: number; email: string }, [number | null]>
Try it in the browser: https://www.typescriptlang.org/play/#code/PTAEBUE8AcFMGUCKAZ...It handles joins with correct nullability, CTEs, subqueries, window functions, INSERT/UPDATE/DELETE with RETURNING, and DDL. At runtime it's a 3.8 KB wrapper for pg or postgres.js, and it can take your schema from Kysely, Drizzle or Prisma.
It needs TypeScript 7 and only supports Postgres. Each extra query adds about 6 ms of compile time (numbers in the README).
Feedback is welcome, especially queries you think should type-check but don't.