Knex vs Kysely
Knex vs Kysely compared for 2026: Knex 3.3 (the long-standing JavaScript SQL query builder with a migrations and seeds CLI) vs Kysely 0.29 (a zero-dependency, fully typed TypeScript query builder inspired by Knex). Includes which query mistakes each type checker catches, query and insert speed, generated SQL, undefined/null handling and how each migrator behaves when a migration fails halfway.
Quick Answer
Knex and Kysely are both SQL query builders for Node.js rather than ORMs: you write queries in JavaScript and get SQL with bound parameters. Knex 3.3.0 (26 June 2026) has been the default for years, works the same from plain JavaScript or TypeScript, supports PostgreSQL, MySQL, MariaDB, SQLite, SQL Server and Oracle, and ships a CLI for migrations and seeds. Kysely 0.29.9 (12 November 2026), which says it was inspired by Knex, is written for TypeScript: you describe your database as an interface and every table, column, alias, join and result row is checked by the compiler. In our runs on 28 November 2026 Kysely caught all five query mistakes we planted while Knex, even with row-type generics, caught none of six. Kysely was faster at inserts (66-72 ms vs 101-200 ms for 20,000 rows) and point selects (523-606 ms vs 801-863 ms for 20,000), while Knex built SQL strings faster. The biggest operational difference was migrations: when a second migration failed on SQLite, Knex rolled the whole batch back, and Kysely kept the first migration and left the half-created table behind, because it only wraps migrations in a transaction on dialects with transactional DDL.
Last updated November 28, 2026. Covers Knex 3.3.0 (26 June 2026) and Kysely 0.29.9 (12 November 2026); package metadata, changelogs, release notes, docs, source and repository data read on 28 November 2026, plus same-machine type-checking, query, insert, SQL-generation and failed-migration runs we did that day.
| Feature | Knex | Kysely |
|---|---|---|
| Licence & Repository | MIT; knex/knex, ~20.3k stars | MIT; kysely-org/kysely, ~14.4k stars |
| Latest Release (Nov 2026) | 3.3.0 on 26 Jun 2026 | 0.29.9 on 12 Nov 2026 (0.28.20 same day) |
| Built For | JavaScript, types optional | TypeScript-first |
| Dependencies & Install | 14 direct deps; 22 packages + driver in our install | 0 deps; 1 package + driver in our install |
| Runtime Requirement | Node.js >= 16 | Node.js >= 22 (0.28.x: >= 20); Deno, Bun, Workers, browsers via dialects |
| Built-in Dialects | PostgreSQL, MySQL, MariaDB, SQLite (sqlite3/better-sqlite3), MSSQL, Oracle; CockroachDB/Redshift via pg | PostgreSQL, MySQL, MSSQL, SQLite, PGlite; many community dialects |
| Compile-time Checking of Queries | Row generics only; caught 0 of 6 planted mistakes | Full; caught 5 of 5 planted mistakes |
| Result Row Types | Inferred for plain column names; 'table.col' and aliases become any | Exact, including aliases, joins and subqueries |
| Migrations | knex CLI and API: make, latest, rollback, up, down, list, unlock | Migrator API (kysely/migration); CLI via kysely-ctl 0.22.0 |
| Failed Migration on SQLite | Whole batch rolled back; nothing recorded | Earlier migration kept; failed one's partial DDL left behind |
| Seeds | Built in (seed:make, seed:run) | Not in core |
| Types from an Existing Database | Not built in | kysely-codegen 0.20.0 (separate package) |
| undefined in a WHERE Value | Throws 'Undefined binding(s) detected' at runtime | Compile-time error; at runtime binds null and returns no rows |
| Raw SQL Escape Hatch | knex.raw with ? and ?? bindings | sql template tag |
| Query Cancellation / Timeouts | Per-query .timeout(ms, { cancel: true }) (cancel on MySQL and PostgreSQL) | AbortSignal on execute/stream (0.29.0), ignore/cancel/kill strategies |
| Version & Stability | 3.x, stable API | 0.x, breaking changes possible in minors |
| Release Activity (2026) | 3.2.4 to 3.2.10 and 3.3.0 (Mar-Jun 2026) | 0.29.0 to 0.29.9 (May-Nov 2026); repo pushed 28 Nov 2026 |
| Our Run: insert 20k rows (txn, 100-row batches) | 101-200 ms | 66-72 ms |
| Our Run: 20k point selects by id | 801-863 ms | 523-606 ms |
| Our Run: build + compile 100k join queries | 573-774 ms | 869-1,097 ms |
Knex
Knex is a SQL query builder for Node.js with a chainable API: knex('users').where('id', 1).first() becomes select * from users where id = ? limit 1 with the value bound. You install it alongside a driver (pg, pg-native, mysql, mysql2, sqlite3, better-sqlite3, oracledb or tedious; CockroachDB and Redshift use pg) and it manages a connection pool through tarn.js, by default min 2 and max 10 for PostgreSQL and MySQL (the docs recommend min 0). Besides queries it has a schema builder, transactions, streaming, and a knex CLI that creates and runs migrations (make, latest, rollback, up, down, list, unlock) and seed files, configured in a knexfile. Each migration runs inside a transaction by default. TypeScript types ship with the package and you can pass a row type, knex<User>('users'), but the docs note that qualified or aliased column names such as 'users.id' fall back to any. Knex 3.3.0 (26 June 2026) added a MariaDB driver, RETURNING on MariaDB, an option to bring an external connection pool, and knex.migrate.to/before. It is MIT-licensed, needs Node.js 16 or newer and has about 20.3k GitHub stars.
Pros
- Built-in CLI for migrations and seeds; a failing migration batch on SQLite rolled back completely in our test, leaving no half-applied state
- Works the same from plain JavaScript, with optional TypeScript generics and JSDoc support
- Broadest built-in driver list, including Oracle (oracledb), MariaDB (new in 3.3.0) and CockroachDB/Redshift through pg
- Runtime guard on undefined values: where('id', undefined) threw 'Undefined binding(s) detected' instead of running a query
- Fastest at building SQL strings in our run: 100,000 join queries compiled in 573-774 ms against 869-1,097 ms for Kysely
- Mature and widely used: about 20.3k GitHub stars and years of existing examples and answers to draw on
Cons
- Type checking is shallow: with knex<UserRow>, a misspelled column, a string compared with a number column, a column from an unjoined table, a wrong result type and an insert missing a required column all compiled without errors
- Qualified columns such as 'users.id' type as any, as its own docs state
- Slower in our runs at inserts (101-200 ms vs 66-72 ms for 20,000 rows) and point selects (801-863 ms vs 523-606 ms for 20,000)
- Pulls in 22 packages (lodash, commander, debug, rechoir and others) before you add a driver
- Release pace is slower: last release 3.3.0 in June 2026, repository last pushed the same day
Best For
JavaScript codebases, existing Knex applications, teams that want migrations and seeds in one CLI, and projects on Oracle or older Node.js versions.
Kysely
Kysely is a type-safe, autocompletion-friendly TypeScript SQL query builder. You declare an interface describing your tables and columns, create new Kysely<DB>({ dialect }) and the compiler then knows which tables are in scope, which columns exist, what type each value must be and exactly what each query returns, including aliases and joined subqueries. Core dialects cover PostgreSQL, MySQL, SQL Server, SQLite and PGlite; organisation and community dialects add Postgres.js, Cloudflare D1, PlanetScale, Neon, libSQL and more, and the README says it also runs on Deno, Bun, Cloudflare Workers and in browsers. The package has no dependencies. Migrations are up/down functions run by a Migrator class imported from kysely/migration; the separate kysely-ctl package provides a CLI and kysely-codegen generates types from an existing database. Version 0.29.0 (8 May 2026) added query cancellation through AbortSignal, a ReadonlyKysely type, a PGlite dialect, $pickTables/$omitTables and a SafeNullComparisonPlugin, and requires TypeScript 5.4+. Kysely 0.29.9 (12 November 2026) needs Node.js 22 or newer; the 0.28.x line (Node.js 20+) is still patched. It is MIT-licensed with about 14.4k GitHub stars.
Pros
- Real compile-time checking: all five planted mistakes (typo, wrong value type, unjoined table, wrong result type, missing required insert column) were TypeScript errors, with 'Did you mean email?' hints
- Exact result types, including aliases such as 'posts.title as postTitle' inside joins
- Zero dependencies; installs as a single package next to the driver
- Faster in our runs at inserts (66-72 ms for 20,000 rows) and point selects (523-606 ms for 20,000)
- Modern features in 0.29: AbortSignal query cancellation with a database-side cancel option, ReadonlyKysely, PGlite dialect
- Runs beyond Node.js (Deno, Bun, Workers, browsers) through dialect packages
Cons
- On SQLite (and MySQL) migrations are not wrapped in a transaction: a failing migration left its half-created table and the previous migration committed in our test
- Pre-1.0 (0.29.x): minor versions can break APIs, and 0.29 raised the floor to Node.js 22 and TypeScript 5.4
- No built-in CLI or seeds; you add kysely-ctl, and kysely-codegen to generate types from an existing schema
- Runtime values are not guarded: where('id', '=', undefined) compiled to = ? with null and silently returned no rows (TypeScript does flag possibly-undefined values)
- Slower than Knex at building SQL strings: 869-1,097 ms vs 573-774 ms for 100,000 join queries
Best For
TypeScript backends where you want SQL-shaped code checked by the compiler, especially on PostgreSQL, and teams that would rather not adopt an ORM.
Same idea, different contract: SQL builders with and without a typed schema
Both libraries build SQL from method chains and send it with bound parameters. Our identical join query compiled to the same SQL apart from identifier quoting: Knex's SQLite dialect quoted with backticks, Kysely with double quotes, and both bound the three values (1, 10, 20). The difference is what the builder knows. Knex is untyped at heart: tables and columns are strings, and TypeScript support was added on top. You can write knex<User>('users') to give the builder a row type, and selecting plain column names narrows the result to Pick<User, 'id'>, but the Knex docs say outright that a qualified name like 'users.id' resolves to any because TypeScript cannot look inside the string. Kysely starts from an interface such as interface DB { users: UserTable; posts: PostTable } and checks everything against it: which tables are in scope after a join, which columns exist on them, the value type on the right of a where, and the exact shape of the row each query returns, aliases included. Columns that the database fills in, such as auto-increment ids, are marked Generated<number> so inserts do not require them. If your database already exists, kysely-codegen (0.20.0) can generate the interface from it. The cost of that model is that Kysely only really pays off in TypeScript and that you maintain the interface, by hand or with codegen, alongside migrations.
What the type checker caught
We wrote the same mistakes against both libraries and ran TypeScript 6.0.3 in strict mode. In Kysely 0.29.9, selecting 'emial' failed with 'Did you mean email?'; comparing the numeric id with 'abc' failed; selecting posts.title from a query that never joined posts failed; assigning the string alias postTitle from a join to a number failed; and inserting into posts without the required title failed. Five of five. The Knex 3.3.0 version used knex<UserRow>('users') and join<PostRow>() throughout and contained the same five mistakes plus one more (assigning the result of select('users.id') to a string). It compiled with zero errors. Knex did catch the simplest case: select('id') narrowed the row and assigning id to a string was an error. But a misspelled select('emial') was accepted and typed as a column. Runtime behaviour around missing values goes the other way. Knex refused to compile where('id', undefined) into SQL and threw 'Undefined binding(s) detected when compiling SELECT'. Kysely compiled the same call to where "id" = ? with null bound and returned an empty array with no error, though the TypeScript compiler did reject a number | undefined value at that position. For null, Knex's where('name', null) produced is null, while Kysely's where('name', '=', null) produced = ? and matched no rows; Kysely 0.29's SafeNullComparisonPlugin rewrites it so the null row was found. Empty arrays differ too: Knex turned whereIn('id', []) into where 1 = 0, Kysely emitted in () (accepted by SQLite in our run; check your database).
What we measured: inserts, reads and SQL generation
We ran both against better-sqlite3 13.2.0 (SQLite 3.54.1) on Node.js 22.23.5, pinned to one core, three runs each, with identical schemas: users (20,000 rows) and posts (20,000 rows, indexed on user_id). Inserting 20,000 users inside one transaction in 100-row batches took 101-200 ms with Knex and 66-72 ms with Kysely. Part of that is SQL shape: Knex's SQLite dialect writes multi-row inserts as insert … select … union all select …, while Kysely writes values (?, ?), (?, ?). Twenty thousand point selects by primary key, awaited one after another, took 801-863 ms with Knex and 523-606 ms with Kysely; the same loop with a prepared better-sqlite3 statement took 62-75 ms, which shows that most of the cost per query is the builder and promise overhead rather than SQLite. Reading 10,000 joined rows was a wash (4-5 ms vs 3-4 ms). Building and compiling 100,000 join queries without running them went the other way: Knex toSQL() 573-774 ms, Kysely compile() 869-1,097 ms, because Kysely builds an immutable operation-node tree on each chained call. At about 6-11 microseconds per query either way, SQL generation is rarely what limits a real service, where a network round-trip to PostgreSQL costs far more. Cold imports were close: 58-68 ms and 56 MB RSS for Knex, 75-80 ms and 58-59 MB for Kysely. Installs differed more: Knex plus the driver was 25 packages and 36 MB, Kysely plus the driver 3 packages and 31 MB, most of it the native better-sqlite3 module in both cases.
Migrations: a CLI with batch rollback versus a migrator API
Knex ships its migration tooling in the box. knex migrate:make create_users writes a timestamped stub, migrate:latest runs everything pending as a batch, and rollback, up, down, list and unlock manage the rest, with seed:make and seed:run alongside. The docs say each migration runs in a transaction by default, with disableTransactions or a per-file config.transaction to opt out. Kysely's core provides a Migrator class (imported from kysely/migration since 0.29) that reads up/down functions through a FileMigrationProvider; the CLI is the separate kysely-ctl package (0.22.0), and there is no seed runner in core. Kysely enforces that migrations run in alphanumeric name order unless you set allowUnorderedMigrations, and 0.29.9 fixed timestamps going backwards when a machine's clock jumps, which had caused 'corrupted migrations' errors. We tested failure handling on SQLite with two migrations, the second creating a table and then throwing. Knex rolled back the whole batch: neither table existed afterwards, knex_migrations was empty and migrate:list showed both files pending, so fixing the file and rerunning applied both cleanly. Kysely returned a result with the first migration Success and the second Error; the first table and its kysely_migration row were committed, and the second migration's half_done table was left in the database, so a rerun would fail on create table until it was dropped by hand. The source explains why: Kysely wraps a migration run in a transaction only when the dialect adapter reports transactional DDL, which is true for PostgreSQL and SQL Server and false for SQLite and MySQL in 0.29.9.
Limits, migration path and when not to use each
Do not choose Knex for a new TypeScript codebase if compile-time safety is the reason you want a query builder: in our test its generics did not catch any of the mistakes that matter in review, and anything with a qualified column name becomes any. Do not choose Kysely if your team writes plain JavaScript, if you are stuck on Node.js 20 or older (stay on 0.28.x for 20; there is no supported option for older versions), if you need Oracle without a community dialect, or if you want built-in seeds. Treat 0.x seriously: 0.29.0 removed long-deprecated APIs and raised the TypeScript floor to 5.4. On SQLite and MySQL, write migrations so a failed one can be rerun (create table if not exists, one change per file), because nothing rolls back partial DDL; MySQL commits DDL implicitly, so this applies to Knex there too. Moving from Knex to Kysely is a rewrite of every query, but the APIs are close (Kysely says it was inspired by Knex): selectFrom replaces knex(table), where takes an explicit operator, and you add a DB interface. The kysely-knex package, described on npm as a Kysely dialect for Knex.js, lets Kysely queries run through an existing Knex instance, so both can coexist during a gradual move. Both are free and MIT-licensed, and neither is an ORM: if you want relations, a schema DSL and generated migrations, look at Drizzle or Prisma instead.
Verdict
Pick Kysely for new TypeScript projects. The reason to use it is the compiler: in our test it rejected every query mistake we planted, from a misspelled column to an insert missing a required field, while Knex accepted all of them even with row-type generics. It was also faster at the operations that hit the database. Plan around two things: on SQLite and MySQL its migrator does not wrap migrations in a transaction, so keep each migration small and idempotent (on PostgreSQL it does run them in one transaction), and budget for occasional breaking changes while it is still 0.x and on Node.js 22+. Pick Knex if your code is plain JavaScript, if you already have a Knex application (rewriting working queries for types alone rarely pays), if you need Oracle or Node.js older than 20, or if you want migrations and seeds handled by one built-in CLI with a failed batch rolled back cleanly. If you want typed queries but also an ORM-style schema and migrations generator, compare Drizzle before choosing either.