explaingit

kysely-org/kysely

13,787TypeScriptAudience · developerComplexity · 2/5Setup · moderate

TLDR

A TypeScript SQL query builder that catches database errors at compile time by letting you describe your schema as types, so missing tables, wrong columns, and bad values are flagged in your editor before the code ever runs.

Mindmap

mindmap
  root((Kysely))
    What it does
      Type safe SQL builder
      Compile time checks
      Schema as types
    SQL Features
      SELECT INSERT UPDATE
      JOIN subqueries CTEs
      Transactions
      Raw SQL escape hatch
    Platforms
      Node.js Deno Bun
      Cloudflare Workers
      Browser
    Databases
      PostgreSQL MySQL
      SQLite MSSQL
    Audience
      TypeScript developers
      Backend engineers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Write type-safe SQL queries in TypeScript so column name typos and wrong value types fail at compile time instead of runtime.

USE CASE 2

Build a Node.js backend that queries PostgreSQL, MySQL, or SQLite with full editor autocomplete for table and column names.

USE CASE 3

Run type-safe database queries in serverless environments like Cloudflare Workers or Deno.

USE CASE 4

Combine the typed query builder with raw SQL strings for edge cases the type system cannot express.

Tech stack

TypeScriptNode.jsDenoBun

Getting it running

Difficulty · moderate Time to first run · 30min

You need to define your database schema as TypeScript types before queries become type-safe, requires a database server or SQLite file to connect to.

In plain English

Kysely (pronounced Key-Seh-Lee) is a library for building SQL queries in TypeScript. Its defining feature is that it checks your queries at compile time, before the code ever runs. When you reference a table or column that does not exist, or when you try to assign a value of the wrong type to a column, TypeScript catches the error immediately in your editor rather than at runtime. The way this works is that you describe your database schema to Kysely as TypeScript types. From that point on, every time you write a query, the library uses those types to verify that the tables and columns you reference are real and that the values you use are the right kind. The result of each query is also typed, so you know exactly which columns will come back and what their types are, including column aliases you create inside the query. Your code editor can also use these types to autocomplete table names, column names, and method names as you type. Kysely covers the common SQL operations: SELECT, INSERT, UPDATE, DELETE, JOIN, subqueries, CTEs (the WITH keyword), transactions, and more. For cases where the static type system cannot express what you need, there is an escape hatch that lets you write raw SQL strings and still integrate them with the typed query builder. The library runs on Node.js, Deno, Bun, Cloudflare Workers, and in web browsers. It has built-in dialects for PostgreSQL, MySQL, Microsoft SQL Server, and SQLite. The community has built additional dialects for other databases. It is available on npm and JSR. Documentation lives on kysely.dev and the project has a Discord server for questions.

Copy-paste prompts

Prompt 1
I have a PostgreSQL database with a users table. Show me how to define the Kysely TypeScript types for it and write a SELECT query that returns typed rows.
Prompt 2
How do I run a JOIN query between two tables in Kysely and make sure TypeScript knows the exact shape of the returned rows?
Prompt 3
I need to insert a new row and get the inserted row back using Kysely with PostgreSQL. Write the TypeScript code for that.
Prompt 4
How do I set up Kysely with a SQLite database in a Cloudflare Worker? Walk me through the dialect configuration.
Prompt 5
Show me how to use a Kysely transaction to run two INSERT statements and roll back if either fails.
Open on GitHub → Explain another repo

← kysely-org on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.