CoachnestCoachnest
Sign InGet Started
Back to course

Mastering CRUD: Build Full-Stack Database Applications

…
—
Contents
1

What Is CRUD and Why It Matters

Reading12mFree
2

CRUD, REST, and HTTP Verbs

Reading14mFree
3

The Data Lifecycle of a Record

Reading11m
4

Course Project Tour: TaskFlow

Video9m
5

Chapter 1 — Quiz

Quiz8m
6

Tables, Rows, Columns & Types

Reading14m
7

Primary Keys & IDs (Auto-increment vs UUID)

Reading13m
8

Relationships: One-to-Many & Many-to-Many

Reading16m
9

Normalization & Schema Design Principles

Reading14m

Modeling TaskFlow with Prisma

Reading13m
11

Chapter 2 — Quiz

Quiz8m
12

INSERT — Creating Rows

Reading13m
13

SELECT — Reading & Filtering

Reading16m
14

UPDATE — Changing Rows Safely

Reading12m
15

DELETE — Removing Rows

Reading11m
16

Live SQL: A Full CRUD Session

Video15m
17

Chapter 3 — Quiz

Quiz9m
18

REST API Design for CRUD Resources

Reading14m
19

HTTP Status Codes That Tell the Truth

Reading12m
20

Scaffolding the API (Express & Next.js)

Reading16m
21

Connecting an ORM (Prisma) to Your Routes

Reading13m
22

Chapter 4 — Quiz

Quiz8m
23

Building the Create Endpoint End-to-End

Reading15m
24

Reading a Single Resource

Reading11m
25

Listing Collections

Reading13m
26

Live Coding: Create & Read

Video16m
27

Chapter 5 — Quiz

Quiz8m
28

PUT vs PATCH: Full vs Partial Updates

Reading13m
29

Authorization: Who Can Change This Row?

Reading12m
30

Soft Delete, Hard Delete & Restore

Reading14m
31

Idempotency & Concurrency Control

Reading13m
32

Chapter 6 — Quiz

Quiz9m
33

Input Validation with Zod

Reading14m
34

Mass Assignment & Over-Posting

Reading11m
35

SQL Injection & Safe Queries

Reading13m
36

Consistent Error Handling

Reading12m
37

Chapter 7 — Quiz

Quiz9m
38

Offset vs Cursor Pagination

Reading15m
39

Filtering & Dynamic WHERE Clauses

Reading13m
40

Safe Sorting & Full-Text Search

Reading14m
41

Indexing for Fast Reads

Reading13m
42

Chapter 8 — Quiz

Quiz9m
43

Forms & Creating Records from the UI

Reading14m
44

Fetching & Displaying Data

Reading13m
45

Optimistic Updates & Deletes

Reading14m
46

Building the TaskFlow UI

Video17m
47

Chapter 9 — Quiz

Quiz8m
48

Transactions & Data Integrity

Reading15m
49

Testing Your CRUD Endpoints

Reading14m
50

Caching, N+1 & Performance

Reading13m
51

Deploying & Migrating Safely

Reading14m
52

Chapter 10 — Final Quiz

Quiz10m
←→navigate lessons
Chapter 2 of 10·Chapter 2 — Designing the Data Model
Lesson 10 of 52Reading13 min

Modeling TaskFlow with Prisma

Modeling TaskFlow with Prisma¶

We'll use Prisma, a type-safe ORM, to turn our schema into typed code. The Prisma schema is a single readable file that maps to database tables.

schema.prisma¶

prisma
41 lines
1generator client {
2  provider = "prisma-client-js"
3}
4
5datasource db {
6  provider = "postgresql"
7  url      = env("DATABASE_URL")
8}
9
10model User {
11  id        String   @id @default(uuid())
12  email     String   @unique
13  name      String
14  tasks     Task[]
15  createdAt DateTime @default(now())
16}
17
18model Task {
19  id          String     @id @default(uuid())
20  title       String
21  description String?
22  status      TaskStatus @default(TODO)
23  dueDate     DateTime?
24  owner       User       @relation(fields: [ownerId], references: [id])
25  ownerId     String
26  tags        Tag[]
27  createdAt   DateTime   @default(now())
28  updatedAt   DateTime   @updatedAt
29}
30
31model Tag {
32  id    String @id @default(uuid())
33  name  String @unique
34  tasks Task[]
35}
36
37enum TaskStatus {
38  TODO
39  IN_PROGRESS
40  DONE
41}

Reading the Schema¶

  • ? marks a field optional (nullable) — description String?.
  • @id is the primary key; @default(uuid()) auto-generates it.
  • @unique enforces no duplicates.
  • @updatedAt auto-stamps the row on every write.
  • Task[] on User and User on Task together model the one-to-many relation.
  • Tag[] on both sides models many-to-many; Prisma manages the join table for you.

Apply It¶

bash
2 lines
1npx prisma migrate dev --name init
2npx prisma generate

migrate dev creates the SQL migration and applies it. generate produces a fully typed client. From here, prisma.task.create(...) is autocompleted and type-checked — the foundation for every CRUD operation in the rest of the course.

Previous

Normalization & Schema Design Principles

Next

Chapter 2 — Quiz

Use ← → arrow keys to navigate between lessons