talira

Type-safe SQL query builder for TypeScript

open sourceMITfree

Kysely is a type-safe, autocompletion-friendly SQL query builder for TypeScript, inspired by Knex.js. It only lets a query refer to tables and columns visible at that point, and infers result types, column names and aliases from selects, joins, subqueries and with clauses, with escape hatches such as the sql template tag for what can't be typed at compile time. It has dialects for PostgreSQL, MySQL, Microsoft SQL Server, SQLite and PGlite, and runs on Node.js, Deno, Bun, Cloudflare Workers and in browsers. Sami Koskimäki wrote it, and he and Igal Klebanov lead the project.

Problems it solves

  • write SQL queries in TypeScript with types checked against my database schema
  • a query builder that autocompletes my table and column names
  • build SQL in TypeScript without a full ORM

Features

  • Compile-time checks that queries only use visible tables and columns
  • Result types inferred from selects, joins, subqueries and with clauses
  • Dialects for PostgreSQL, MySQL, SQL Server, SQLite and PGlite
  • Runs on Node.js, Deno, Bun, Cloudflare Workers and browsers
  • sql template tag and dynamic module for queries that can't be typed

Alternatives

The same job

These do what Kysely does.

  1. Prisma ORM One schema. Every query type-safe.
  2. Reylo Import .sql files into TypeScript with types inferred from your live database, plus SQL-first migrations
  3. Knex.js SQL query builder for Node.js with migrations and seeds

Compare Kysely with the top 3