kysely README

The project's README from github.com/kysely-org/kysely. As one markdown file: README.md.

Stand With Ukraine

NPM Version Socket Badge Tests License Issues Pull Requests GitHub contributors NPM Downloads JSR Downloads JSR Score

Join the discussion ⠀⠀⠀⠀⠀⠀⠀

Discord Bluesky

Get started

PostgreSQL MySQL MSSQL SQLite PGlite & more!

Kysely

Kysely (pronounce “Key-Seh-Lee”) is a type-safe and autocompletion-friendly TypeScript SQL query builder. Inspired by Knex.js. Mainly developed for Node.js but also runs on all other JavaScript environments like Deno, Bun, Cloudflare Workers and web browsers.

Kysely makes sure you only refer to tables and columns that are visible to the part of the query you're writing. The result type only has the selected columns with correct types and aliases. As an added bonus you get autocompletion for all that stuff.

As shown in the gif above, through the pure magic of modern TypeScript, Kysely is even able to parse the alias given to pet.name and add the pet_name column to the result row type. Kysely is able to infer column names, aliases and types from selected subqueries, joined subqueries, with statements and pretty much anything you can think of.

Of course there are cases where things cannot be typed at compile time, and Kysely offers escape hatches for these situations. See the sql template tag and the DynamicModule for more info.

All API documentation is written in the typing files and you can simply hover over the module, class or method you're using to see it in your IDE. The same documentation is also hosted here.

If you start using Kysely and can't find something you'd want to use, please open an issue or join our Discord server.

Getting started

Please visit our documentation site kysely.dev to get started. We also have a comprehensive API documentation hosted here, but you can access the same documentation in your IDE by hovering over a class/method/property/whatever.

Core team

Project leads

Responsible for project direction, API design, maintenance, code reviews, community support, documentation, and working on some of the most impactful/challenging things.


Sami Koskimäki

(the author)

Igal Klebanov

(the dynamo)

Honorable mentions

People who had special impact on the project and its growth.


Fernando Hurtado

(1st docs)

Wirekang

(playground)

Tim Griesser

(Knex)

Robin Blomberg

(codegen)

Shoubhit Dash

(prisma idea)

Valtýr Örn Kjartansson

(prisma impl)

Dax Raad

(early adopter)

Theo Browne

(early promoter)

Lee Robinson

(early promoter)

Ethan Resnick

(timely feedback)

Harminder Virk

(dope writeup)

Johan Eliasson

(promoter/educator)

All contributors


Want to contribute? Check out our contribution guidelines.

Powered by Vercel

kysely (kysely-org/kysely)

Searching Database…

14.3K ·GitHub
这是什么东西?Kysely(读作 'Key-Seh-Lee')是一个类型安全、对自动补全很友好的 TypeScript SQL 查询构建器,灵感来自 Knex.js:它会在编译时检查你的查询,并为结果提供类型。
所以它是我加到项目里的库,不是要运行的工具?没错——是一个库。你在 TypeScript 代码里写查询,Kysely 负责生成 SQL,返回的每一行都带有完整的类型。
它在哪里运行——只有 Node.js 这一种选择吗?主要面向 Node.js(按其包元数据要求 Node 22+),但它也能在 Deno、Bun、Cloudflare Workers 以及网页浏览器里运行——而且这个包本身不带任何运行时依赖。
如果查询里有一部分在编译时没法确定类型怎么办?Kysely 正是为这种情况准备了逃生通道:用于原生 SQL 的 sql 模板标签,以及处理动态场景的 DynamicModule。
我需要用 TypeScript 项目才能用好它吗?是的——它就是为 TypeScript 代码库设计的:编译时检查和自动补全都来自静态类型。用纯 JavaScript 调用它也可以,但那样就失去了类型安全,而类型安全正是它的全部意义所在。
类型安全到底能给我带来什么好处?编译时就有保障:你只能引用查询在该位置可见的表和列,而且结果类型会精确包含所选的列,类型和别名都正确——写代码时还有自动补全。
它对别名和子查询处理得有多聪明?非常聪明:它能把 pet.name 这样的别名解析成结果行里一个带类型的 petname 列,还能从所选子查询、连接子查询和 with 语句中推断出列名、别名和类型。
它支持哪些数据库?它的仓库主题标签里列出了 PostgreSQL、MySQL、SQLite 和 Microsoft SQL Server(MSSQL)。
这个名字怎么读?'Key-Seh-Lee'——README 的第一行就说明了这一点。
What are similar projects?sequelize, orm, typeorm, directus, diesel, efcore, pglite, remix
Creator
kysely-org
Size
58.2 MB
Stars
14.3K
Age
5y
Commits · 90 Days