Skip to content

Knex

Medium — good to knowBackend

ELI5 — The Vibe Check

Knex is a SQL query builder for Node.js that's like writing SQL with training wheels. It doesn't try to hide the SQL — it just makes it easier to write and database-agnostic. It's the foundation that many other ORMs (like Objection.js) are built on top of.

Real Talk

Knex.js is a batteries-included SQL query builder for Node.js supporting PostgreSQL, MySQL, SQLite3, Oracle, and MSSQL. It provides a chainable API for building SQL queries, a migration system, and seed files. It operates at a lower level than full ORMs, giving developers more control over generated SQL.

Show Me The Code

const users = await knex('users')
  .select('name', 'email')
  .where('active', true)
  .orderBy('created_at', 'desc')
  .limit(10);

When You'll Hear This

"We use Knex for migrations and raw queries where the ORM is overkill." / "Knex lets us switch between Postgres and MySQL without rewriting queries."

Made with passive-aggressive love by manoga.digital. Powered by Claude.