CodingNic

Introduction to ORMs and Prisma Setup

What Is an ORM?

Introduction to ORMs and Prisma Setup 10 min read

What Is an ORM?

Objectives

By the end of this lesson, you should be able to:

  • Explain what an ORM is, and what it generates under the hood
  • List real trade-offs between raw SQL (Modules 1 and 2) and an ORM
  • Explain why this course teaches raw SQL first

💡 Why this matters: Modules 1 and 2 wrote every query by hand, connection setup, parameterized SQL, transactions. An ORM automates a lot of that, but it’s still just generating the same kind of SQL underneath, understanding that layer first means Prisma never feels like magic.

What ORM Stands For

ORM stands for Object-Relational Mapper, a library that maps rows in a relational database to objects in code, and generates SQL for you based on method calls instead of query strings:

javascript
// Raw SQL (Module 2)
const result = await pool.query('SELECT * FROM students WHERE grade = $1', [10]);

// The same query with an ORM (Prisma, covered starting next lesson)
const students = await prisma.student.findMany({ where: { grade: 10 } });

Both end up running essentially the same SQL against PostgreSQL. The difference is what’s written by hand, and what’s generated.

What an ORM Actually Buys

  • Less repetitive SQL, common operations (find, create, update, delete) become method calls instead of hand-written query strings.
  • Type safety, in a TypeScript project (or with editor tooling in JavaScript), an ORM can catch a typo’d column name before the code ever runs, a raw SQL string can’t.
  • Migrations, a structured, versioned way to evolve a database schema over time (Module 4), instead of hand-written ALTER TABLE statements tracked manually.
  • Relationships made easier, loading a user together with their posts (Module 5) is one method call instead of a hand-written JOIN.

What an ORM Costs

  • Another layer to understand. When something goes wrong, the error might be in the generated SQL, not the code that’s visible.
  • Less control over the exact query, for very specific performance tuning, raw SQL (or an ORM’s own “raw query” escape hatch) is sometimes still the right tool.
  • A learning curve of its own, an ORM’s query API is its own thing to learn, on top of SQL itself.

Why This Course Teaches Raw SQL First

Modules 1 and 2 weren’t a detour, they’re the reason Prisma (starting next lesson) won’t feel like a black box. Every Prisma Client call from here on generates SQL built from exactly the same pieces already covered: SELECT, WHERE, parameterized values, transactions. When something needs debugging, that foundation is what makes the generated SQL readable instead of mysterious.

Try It

  1. Look back at one query from Module 2, and write, in words, what a matching ORM method call might look like (don’t worry about exact Prisma syntax yet, that starts next lesson).
  2. List two things an ORM makes easier, and one thing it makes harder, in your own words.
  3. Explain why understanding raw SQL first makes an ORM easier to learn, not harder.

Recap

  • An ORM maps database rows to objects and generates SQL from method calls, instead of query strings written by hand.
  • It trades some control and directness for less repetition, type safety, and structured migrations.
  • Everything Prisma generates from here on is built from the same SQL concepts already covered in Modules 1 and 2.

Next lesson: installing Prisma and connecting it to PostgreSQL.