Practice & Assessment
Test your understanding of Database Integration with Prisma
Multiple Choice Questions
5Why do you need the PrismaClient singleton pattern in Next.js development?
In a Prisma model, what does the ? symbol after a type mean?
You call prisma.post.findMany() with both include and select at the top level. What happens?
What Prisma error code indicates a unique constraint violation?
Inside a prisma.$transaction interactive callback, which client should you use for queries?
Coding Challenges
1Build 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.
Mini Project
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.
