Skip to content

Kysely

A type-safe TypeScript SQL query builder that checks your queries against your table types.

Stars
14.3k
Forks
456
Licence
MIT
Language
TypeScript
Last update
4 days ago
Type
Library

What it is

Kysely is a library for writing SQL queries in TypeScript. You chain method calls instead of writing raw SQL strings, and TypeScript checks that the tables and columns you use exist and returns result types that match what you selected. It is inspired by Knex.js and is mainly aimed at Node.js, though the README says it also runs in Deno, Bun, Cloudflare Workers and browsers.

  • Build type-checked SELECT queries with joins, subqueries and aliases
  • Write INSERT, UPDATE and DELETE statements against a typed database schema
  • Use the sql template tag for raw SQL fragments the typings cannot cover
  • Run queries in the browser or on edge runtimes such as Cloudflare Workers, as the README describes

Great for

  • TypeScript developers who want SQL control without losing compile-time type checks
  • Teams building Node.js backends that query PostgreSQL, MySQL, SQLite or MSSQL
  • Developers who want editor autocompletion for table and column names
  • Projects that need an escape hatch to raw SQL for cases the types cannot express

Not ideal for

  • Developers not using TypeScript, since the main benefit depends on the type system
  • People who want a full ORM with models, migrations and relationships handled for them, as Kysely is a query builder
  • Beginners learning SQL for the first time, who may do better writing plain SQL first
Step-by-step guide: how to use KyselyInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Node.js or another JavaScript runtime · TypeScript (recommended) · A supported database such as PostgreSQL, MySQL, SQLite or MSSQL

    Install from npm

    npm install kysely
  2. 2

    Run it

    • Install the package with your package manager
    • Define a TypeScript interface describing your database tables
    • Create a Kysely instance with a dialect for your database
    • Write a query and let your editor show the available tables and columns
    • Visit kysely.dev for the getting-started guide
  3. 3

    Get the most out of it

    • Use the API docs hosted at kysely-org.github.io/kysely-apidoc for method details
    • Try the playground linked from the README at kyse.link to experiment
    • Use the sql template tag for cases the type system cannot express
    • Join the Discord server linked in the README to ask questions

Downloads

Strengths

  • Type inference carries selected columns and aliases through queries, per the README
  • API documentation is in the typing files and visible on hover in the IDE
  • Supports several SQL dialects, including PostgreSQL, MySQL, SQLite and MSSQL

Trade-offs

  • Its value depends heavily on TypeScript, so JavaScript-only projects gain little
  • The README notes some things cannot be typed at compile time and need escape hatches
  • As a query builder, it does not provide ORM features such as models or relationship management

How it compares

ProjectStarsTypeLevelUpdatedBest for
kysely (this)14.3kLibraryintermediate4 days agoTypeScript developers who want SQL control without losing compile-time type checks
typeorm36.7kLibraryintermediate8 days agoNode.js or TypeScript developers building apps backed by a relational database
sequelize30.3kLibraryintermediate5 days agoNode.js backend developers who use a relational SQL database
sqlc18.4kDev toolintermediate4 days agoGo developers who prefer writing plain SQL over using an ORM
usql10.2kCLIbeginner4 days agoDevelopers who use several different databases and want one tool for all of them
knex20.3kLibraryintermediate4 months agoNode.js developers who need to talk to a SQL database from application code

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.