Script Valley
Next.js: Full-Stack React Applications
Database Integration with Prisma/Assessment

Practice & Assessment

Test your understanding of Database Integration with Prisma

Multiple Choice Questions

5
1

Why do you need the PrismaClient singleton pattern in Next.js development?

2

In a Prisma model, what does the ? symbol after a type mean?

3

You call prisma.post.findMany() with both include and select at the top level. What happens?

4

What Prisma error code indicates a unique constraint violation?

5

Inside a prisma.$transaction interactive callback, which client should you use for queries?

Coding Challenges

1
1

Build a Paginated Blog with Database

Set up Prisma with SQLite (easier for local dev: provider = 'sqlite', url = 'file:./dev.db'). Define Post and Category models: Post has id (cuid), title (String), content (String?), published (Boolean, default false), categoryId (String), createdAt (DateTime, default now); Category has id (cuid) and name (String, unique); Post belongs to one Category. Run migrate dev. Seed 20 posts across 3 categories using prisma.post.createMany in a seed script (prisma/seed.ts). Build /blog?page=N showing 5 posts per page with next/previous links, and /blog/[id] showing a single post with its category name via include. Time estimate: 30 minutes.

Medium

Mini Project

1

Task Management App with Full Database CRUD

Build a task management app backed by Prisma and SQLite. Schema: User (id, email unique, name), Task (id, title, description?, status enum: TODO/IN_PROGRESS/DONE, priority enum: LOW/MEDIUM/HIGH, dueDate DateTime?, userId, createdAt). Seed 3 users and 10 tasks. Features: /tasks page (Server Component) listing all tasks with filters for status and priority via search params; paginated with 5 per page; Server Action createTask with Zod validation (title required, valid status/priority enum values, optional dueDate as ISO string); Server Action updateTaskStatus accepting id and new status; Server Action deleteTask with Prisma error handling for P2025; /tasks/[id] detail page; unique constraint on task title per user (@@unique([title, userId])). Handle the unique constraint gracefully in createTask and return a user-friendly error.

Hard
Practice & Assessment โ€” Database Integration with Prisma โ€” Next.js: Full-Stack React Applications โ€” Script Valley โ€” Script Valley