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
10

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

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 7 of 10·Chapter 7 — Validation, Errors & Security
Lesson 35 of 52Reading13 min

SQL Injection & Safe Queries

SQL Injection & Safe Queries¶

SQL injection is decades old and still a top vulnerability. It happens when user input is concatenated into a query string.

The Classic Hole¶

ts
3 lines
1// ❌ NEVER do this
2const q = `SELECT * FROM users WHERE email = '${email}'`;
3db.query(q);

A user enters as their email:

' OR '1'='1

The query becomes ... WHERE email = '' OR '1'='1' — which matches every row. Worse inputs can drop tables or read other users' data.

The Fix: Parameterized Queries¶

Never build SQL by string concatenation. Use placeholders and pass values separately:

ts
2 lines
1// ✅ parameterized
2db.query("SELECT * FROM users WHERE email = $1", [email]);

The driver sends the query and the data on separate channels. Input is treated as a value, never as executable SQL.

ORMs Parameterize for You¶

ts
1 line
1await prisma.user.findMany({ where: { email } }); // safe by construction

This is a major reason to use a query builder or ORM: parameterization is the default.

The Danger Zone: Raw Queries¶

When you must drop to raw SQL, use the tagged-template / parameter form — not string interpolation:

ts
5 lines
1// ✅ Prisma tagged template — values are parameterized
2await prisma.$queryRaw`SELECT * FROM users WHERE email = ${email}`;
3
4// ❌ $queryRawUnsafe with concatenation — back to square one
5await prisma.$queryRawUnsafe(`SELECT * FROM users WHERE email = '${email}'`);

You Can't Parameterize Identifiers¶

Placeholders work for values, not column or table names. If you must build a dynamic ORDER BY column, whitelist allowed columns:

ts
2 lines
1const ALLOWED = { createdAt: "created_at", title: "title" } as const;
2const col = ALLOWED[sortKey] ?? "created_at"; // reject anything else

This connects directly to safe sorting in Chapter 8.

Previous

Mass Assignment & Over-Posting

Next

Consistent Error Handling

Use ← → arrow keys to navigate between lessons