Skip to content
Tutorials Center
My learning

Topics

Prisma ORM Tutorial

Learn Prisma ORM step by step: 36 lessons in 9 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is Prisma ORM? Learn what Prisma ORM is, how its schema, generated client and migrations fit together, and when to choose it over raw SQL or other Node.js database tools.
  2. 2 Installing Prisma and Setting Up a Project Install Prisma ORM in a Node.js and TypeScript project, run prisma init, understand the files it creates, configure a driver adapter and generate the client.
  3. 3 Configuring the Datasource, Generator and prisma.config.ts Understand the generator and datasource blocks, the prisma.config.ts file, environment variables, multiple databases and which adapter matches PostgreSQL, MySQL or SQLite.
  4. 4 Your First Prisma Queries Walk through a complete first Prisma script: connect, create records, read them back, update, delete and disconnect, with a runnable stand-in for the client.
  5. 5 The Prisma CLI and Prisma Studio A tour of the Prisma CLI: init, generate, validate, format, db push, migrate, db pull, db seed and studio, with a guide for which command to use when.

Schema and Models

  1. 6 Models and Fields in the Prisma Schema Learn the Prisma schema language: how models become tables, how fields, optional and list types, default values and comments work, with a SQL-generating stand-in.
  2. 7 Prisma Field Types and Attributes Learn every Prisma scalar type (String, Int, BigInt, Float, Decimal, Boolean, DateTime, Json, Bytes), how they map to TypeScript and why money should not be a Float.
  3. 8 Enums, Native Types and Scalar Lists Define Prisma enums for fixed sets of values, use them in queries and defaults, map their names, and learn when scalar lists and Json are better than a new table.
  4. 9 Identifiers, Unique Constraints, Indexes and Name Mapping Choose primary keys (autoincrement, uuid, cuid), build composite keys, add unique constraints and indexes, and map model and field names to existing table and column names.

Client Queries

  1. 10 Creating and Reading Records with Prisma Client Learn the Prisma Client methods to create and read data: create, createMany, findUnique, findFirst, findMany, the OrThrow variants and count, with a runnable stand-in.
  2. 11 Filtering with where: Operators, AND, OR and NOT Master Prisma's where option: equality, comparison, string filters, in, null checks, AND, OR, NOT and case-insensitive search, with a stand-in engine you can experiment with.
  3. 12 Selecting Fields, Sorting and Pagination Choose which fields to return with select and omit, sort with orderBy, paginate with skip/take or cursors, and understand why cursor pagination scales better on large tables.
  4. 13 Updating, Deleting and Upserting Records Change and remove data with Prisma Client: update, updateMany, atomic increment, delete, deleteMany and upsert, plus the P2025 not-found error and soft deletes.
  5. 14 Counting, Aggregating and Grouping with Prisma Summarize data with Prisma Client: count, aggregate (_sum, _avg, _min, _max), groupBy with having and ordering, and when to use these instead of loading rows into JavaScript.

Relations

  1. 15 One-to-Many Relations in Prisma Model one-to-many relations with @relation, foreign keys and relation fields, learn how the two sides fit together, and query related data with include and some/every/none.
  2. 16 One-to-One and Many-to-Many Relations in Prisma Model one-to-one relations with a unique foreign key and many-to-many relations with implicit or explicit join tables, and learn when each style is the right choice.
  3. 17 include, select and Nested Writes in Prisma Load related data with include and nested select, filter and sort relations, count relations, and create or update several related records in one call with nested writes.
  4. 18 Self-Relations, Named Relations and Referential Actions Model trees and followers with self-relations, name relations when two models are linked twice, and control deletes with onDelete and onUpdate referential actions.

Migrations

  1. 19 The Prisma Migrate Workflow Learn how Prisma Migrate turns schema changes into SQL migration files, how migrate dev and migrate deploy differ, and what the _prisma_migrations table records.
  2. 20 Migration Files, Customizing SQL and Drift Read and edit Prisma migration.sql files safely with --create-only, handle renames and data backfills, and understand schema drift, shadow databases and migrate reset.
  3. 21 db push, db pull and Baselining Know when to use prisma db push for prototyping, db pull to introspect an existing database, and how to baseline production so Prisma Migrate can take over safely.
  4. 22 Seeding and Data Migrations Write an idempotent Prisma seed script with upsert, configure prisma db seed, and learn the difference between seed data, reference data and one-off data migrations.

Transactions and Raw SQL

  1. 23 Transactions: Atomic Writes in Prisma Understand ACID transactions and the three ways Prisma gives you atomic writes - nested writes, the $transaction array form and interactive transactions - with rollback examples.
  2. 24 Interactive Transactions, Isolation and Retries Configure Prisma interactive transactions with timeout, maxWait and isolationLevel, prevent lost updates with optimistic concurrency, and retry on write conflicts and deadlocks.
  3. 25 Raw Queries with $queryRaw Run raw SQL from Prisma with $queryRaw and $executeRaw, bind parameters safely with tagged templates, avoid SQL injection, and use Prisma.sql, Prisma.join and Prisma.raw correctly.
  4. 26 TypedSQL and Raw SQL Safety Write raw SQL in .sql files and let Prisma TypedSQL generate type-safe functions, plus a checklist for keeping hand-written SQL safe, tested and maintainable.

Performance and Patterns

  1. 27 Solving the N+1 Query Problem Spot and fix the N+1 query problem in Prisma with include, select, relationLoadStrategy and batching, and learn to count queries so you can prove an improvement.
  2. 28 Pagination: Offset and Cursor Paginate Prisma results with skip and take or with cursor-based keyset pagination, understand why offset gets slow and unstable, and build a stable next-page API.
  3. 29 Indexes and Query Plans Speed up Prisma queries with @@index, @unique and composite indexes, learn how the leftmost-prefix rule works, and read EXPLAIN output to confirm an index is used.
  4. 30 Client Extensions Customize Prisma Client with $extends - add computed result fields, custom model methods, query hooks for soft delete and auditing, and client-level helpers - with a runnable stand-in.
  5. 31 Connection Pooling and Logging Configure connection pools with Prisma driver adapters, avoid too-many-connections errors in serverless apps, reuse one PrismaClient, and log queries with durations.

Testing and Deployment

  1. 32 Testing Prisma Code Test code that uses Prisma with unit tests and fakes, integration tests against a real test database, per-test cleanup by rollback or truncate, and seeded fixtures with node:test.
  2. 33 Deploying Prisma Apps Deploy a Prisma application safely - run migrate deploy in CI, generate the client at build time, use Docker and serverless correctly, and apply zero-downtime migration rules.

Projects and Practice

  1. 34 Project: A Blog API Build a small blog REST API with users, posts and tags, a repository layer shaped like Prisma Client, cursor pagination and proper errors, with the real Prisma schema and a runnable Node stand-in.
  2. 35 Project: Inventory and Orders with Transactions Build an order system where placing an order checks and decrements stock atomically, handles concurrent buyers, is idempotent with a unique key, and rolls back on failure.
  3. 36 Prisma Practice Exercises Practice Prisma with graded exercises on migrations, transactions, raw SQL, N+1, pagination and indexes, with hints, runnable stand-in checks and worked solutions.