Query Builder
ELI5 — The Vibe Check
A query builder lets you build database queries by chaining methods instead of writing raw SQL. It's like assembling a sentence with Lego blocks — .where(), .orderBy(), .limit() — instead of typing out the whole SQL sentence yourself.
Real Talk
A query builder is a library or API that allows developers to construct database queries programmatically using method chaining. It provides SQL-like functionality with the safety of parameterized queries and cross-database compatibility, sitting between raw SQL and a full ORM.
Show Me The Code
const users = await db('users')
.where('active', true)
.orderBy('created_at', 'desc')
.limit(10);
When You'll Hear This
"Use the query builder instead of raw SQL for safety." / "Knex is a popular query builder for Node.js."
Related Terms
Active Record
Active Record is an ORM pattern where each database row becomes an object that knows how to save itself.
Migration
A migration is a versioned script that modifies your database schema — adding a column, creating a table, changing a type.
ORM (Object-Relational Mapper)
An ORM is like a translator between your code and your database. Instead of writing scary SQL, you just write normal code like `User.
Schema
A database schema is the blueprint of your database — which tables exist, what columns they have, what types they are, and how they relate to each other.