PACKAGE · ORM & DATABASE

knex

A batteries-included SQL query & schema builder for PostgresSQL, MySQL, CockroachDB, MSSQL and SQLite3

WEEKLY DOWNLOADS 7.1M
STARS 20.3K
FORKS 2.2K
OPEN ISSUES 777
INSTALL SIZE 3.3 MB
UNPACKED SIZE 941.4 kB
LAST UPDATED 1y ago
DOWNLOAD TRENDS

knex downloads · last 12 months

Download trends for knex1 download series from Nov 2025 to Oct 2026. Use left and right arrow keys to inspect monthly values.06.5M13.0M19.5M26.1MNov 2025FebMayAugOct 2026
knex
ABOUT KNEX

Knex is a SQL query and schema builder for JavaScript applications. It provides a programmatic way to compose database queries and define schema changes for PostgreSQL, MySQL, CockroachDB, Microsoft SQL Server, and SQLite3, while targeting SQL databases rather than hiding them behind a single database model.

Its design centers on building SQL through a JavaScript API, giving application code a structured alternative to assembling query strings manually. Knex is suited to developers who want to work with relational databases directly, express queries and schema operations in code, and retain database-specific choices across supported engines.

The query builder and schema builder are its core APIs: use the former to construct database operations and the latter to describe schema changes. This makes it possible to keep query construction and schema work in the application’s JavaScript code, with database selection configured for one of the supported dialects.

Knex fits JavaScript and Node.js workflows that need relational database access across PostgreSQL, MySQL, CockroachDB, MSSQL, or SQLite3. Its SQL-focused approach can sit beneath application frameworks or services that need database queries, and its schema-building capability supports workflows where developers manage database structure alongside application code.

At version 3.3.0, Knex has 1.9 million weekly downloads, 20.3K GitHub stars, and 2.2K forks, indicating an established project with substantial ecosystem use. Its unpacked package size is 941.4 kB, which is worth considering when evaluating dependency footprint; the supplied package details do not specify runtime performance or provide a benchmark comparison.

Knex is a query and schema builder, not a higher-level object-relational mapping layer, so developers should expect to work with SQL-oriented concepts. Its supported database list is explicit, and projects requiring a different database or a more abstract data model should check compatibility and API fit before adopting it.

WHEN TO USE
  • Use Knex’s query builder to compose SQL queries in JavaScript for PostgreSQL, MySQL, CockroachDB, MSSQL, or SQLite3.
  • Use the schema builder when you want database structure changes expressed as JavaScript rather than maintained only as hand-written SQL.
  • Choose Knex when your application should retain SQL-oriented query construction instead of relying on a higher-level object-relational mapping model.
  • Use it when one codebase needs to target one of Knex’s explicitly supported SQL database engines through a shared builder approach.
  • Use Knex as the database-access layer beneath JavaScript services or frameworks that need queries against a supported relational database.
  • Consider it when your team wants query and schema-building capabilities in the same package and can account for its 941.4 kB unpacked size.
WHEN NOT TO USE
  • Avoid Knex if your database is not PostgreSQL, MySQL, CockroachDB, MSSQL, or SQLite3; choose a database access tool that explicitly supports your engine.
  • Avoid Knex if you want a higher-level object-relational mapping API rather than SQL-oriented query construction; select a tool designed around that abstraction.
  • Avoid Knex if your project requires direct, hand-authored SQL as its primary query workflow; use a workflow centered on SQL files or statements instead.
  • Avoid relying on Knex for database schema workflows if your team does not want schema operations expressed through its schema builder; keep schema changes in your chosen migration format.
  • Reconsider Knex if the 941.4 kB unpacked size conflicts with your dependency-footprint constraints; evaluate a lighter database-access approach.
  • Do not assume equivalent behavior or performance across database engines from the shared builder API; verify dialect-specific requirements against the target database before adopting Knex.

CORRECTIONS

Spot wrong data here?

A short note helps us fix it.

Anonymous · No account · No email back

COMPARISONS 6
knex vs mongoose ★ 27.5K · 8.8M/wk knex vs typeorm ★ 36.7K · 7.3M/wk knex vs kysely ★ 14.4K · 31.4M/wk knex vs sequelize ★ 30.3K · 4.3M/wk knex vs prisma ★ 26 · 25.3M/wk knex vs drizzle-orm ★ 36.4K · 47.8M/wk