Where Prisma Fits
Prisma Fundamentals
Chapter 1 ยท What an ORM Is & Where Prisma Fits
Almost every application stores data in a database, and almost every application is written in a language that isn't SQL. Something has to sit between the two. This course is about one popular choice for Node.js and TypeScript, Prisma. This first chapter explains the problem Prisma solves, the other ways of solving it, and how Prisma is put together, before any code is written in Chapter 2.
The Problem: Two Different Worlds
A relational database stores data in tables of rows and columns, linked by foreign keys. Your
application works with objects: a user with a list of posts, each with
its own author. Converting between the two by hand is repetitive and error-prone:
The SQL is just text, so typos in column names only show up when the code runs, and the results carry no type information. This gap between the table model and the object model is sometimes called the object-relational impedance mismatch.
Three Ways to Bridge the Gap
| Approach | Examples (Node.js) | How you write queries | Trade-off |
|---|---|---|---|
| Database driver | pg, mysql2, better-sqlite3 | Raw SQL strings | Full control, but no type safety and a lot of repetitive code |
| Query builder | Knex, Kysely | JavaScript methods that build SQL | Close to SQL, with safer composition; you still map results yourself |
| ORM | Sequelize, TypeORM, Prisma, Drizzle | Methods on models or a generated client | Much less code and better types, at the cost of some control and an extra layer to learn |
ORM stands for object-relational mapper: a library that maps database tables to objects in your code, so you can read and write data without writing most of the SQL yourself.
How Prisma Is Different
Many ORMs have you describe your tables with classes in your application code. Prisma instead starts from a single schema file, written in its own small language, and generates a type-safe client from it:
The typo that slipped past the plain driver is now caught by TypeScript before the code runs, and your editor can autocomplete every field and query option.
| ORM | Where the data model lives | Style |
|---|---|---|
| Sequelize | JavaScript model definitions | A long-established ORM; types added on top |
| TypeORM | TypeScript classes with decorators | Close to ORMs in Java and C# |
| Drizzle | TypeScript table definitions | Deliberately SQL-like queries, very thin layer |
| Prisma | A separate schema.prisma file | Generated client with an object-style query API |
None of these is simply "best." Prisma's strengths are its readable schema, strong typing, and polished migration tooling. Its costs are an extra generation step, its own schema language to learn, and a query API that's further from SQL than Drizzle or a query builder.
The Parts of Prisma
| Part | What it does | Covered in |
|---|---|---|
| Prisma schema | Describes your database connection, data models and relations | Chapters 3, 7, 8 |
| Prisma Client | The generated, type-safe library your code uses to query the database | Chapters 5, 6, 9 |
| Prisma Migrate | Turns changes to the schema into SQL migration files and applies them | Chapter 4 |
| Prisma Studio | A browser-based viewer and editor for your data | Chapter 5 |
| Prisma CLI | The prisma command that runs generation, migrations and Studio | Throughout |
The company behind Prisma also sells hosted products, such as a managed Postgres database and a connection pooling and caching service. They're optional; everything in this course works with a database you run yourself.
Which Databases, and Which Version?
This course uses Prisma ORM 7, the current stable release line. It supports PostgreSQL, MySQL, MariaDB, SQLite, Microsoft SQL Server, CockroachDB and MongoDB. Examples use SQLite for quick experiments and PostgreSQL for anything closer to production.
prisma.config.ts settings file and moved to ES
modules. Many older tutorials show the previous setup, so if a guide doesn't match what you see, check which
version it was written for. Chapter 2 sets up a project the Prisma 7 way.
Hands-On Exercises
In your own words, explain the "object-relational impedance mismatch," and give two concrete problems with the plain-driver example at the start of this chapter.
๐ View solutionFor each project, suggest whether a plain driver, a query builder, or an ORM such as Prisma would suit best, and why: (a) a one-off script that copies data between two tables; (b) a medium-sized web app written in TypeScript by a small team; (c) a reporting tool made almost entirely of complex hand-tuned SQL.
๐ View solutionFind a Prisma tutorial online and work out which Prisma version it was written for. What clues in its code or setup instructions tell you, based on this chapter?
๐ View solutionChapter 1 Quick Reference
- An ORM (object-relational mapper) maps database tables to objects in code
- Options range from raw drivers (
pg) through query builders (Knex, Kysely) to ORMs (Sequelize, TypeORM, Drizzle, Prisma) - Prisma is schema-first:
schema.prismadescribes the data, and a type-safe client is generated from it - Its parts: the schema, Prisma Client, Prisma Migrate, Prisma Studio and the
prismaCLI - This course uses Prisma ORM 7: a TypeScript client with driver adapters,
prisma.config.tsand ES modules - Prisma 8 is a release candidate for some databases; version 7 stays the stable choice
- You still need SQL to understand what an ORM is doing