knex
A batteries-included SQL query and schema builder for PostgreSQL, MySQL, SQLite, MSSQL, and more.
knex
Node.jsA batteries-included SQL query and schema builder for PostgreSQL, MySQL, SQLite, MSSQL, and more.
Fit
Bundle (gzip)
90.6 kB
329.5 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Writing raw SQL strings across multiple database engines is fragile and non-portable, while a full ORM is often heavier than you want when you just need composable, safe queries and migrations.
What It Does
knex provides a fluent, chainable query builder that compiles to SQL for many engines, plus a migration and seeding system. It is a middle ground between raw SQL and a full ORM, and underpins tools like Objection.js.
Installation
npm install knex pgUsage Example
import knexFactory from "knex";
const knex = knexFactory({
client: "pg",
connection: process.env.DATABASE_URL,
});
const activeUsers = await knex("users")
.select("id", "email")
.where("active", true)
.orderBy("created_at", "desc")
.limit(10);
console.log(activeUsers);Related packages
Role and attribute based access control (RBAC + ABAC) for Node.js with a fluent, readable API.
bcryptjsNode.jsPure JavaScript bcrypt password hashing — no native dependencies, same API as bcrypt, works anywhere Node.js runs.
bullmqNode.jsPremium message queue and job scheduler for Node.js backed by Redis — reliable background job processing with retries, priorities, and rate limiting.
casbinNode.jsA powerful authorization library that supports RBAC, ABAC, ACL and more via configurable policy models.
dotenvNode.jsLoad environment variables from a `.env` file into `process.env` — the standard way to manage configuration in Node.js apps.