0
0
NextJSframework~20 mins

Prisma ORM setup in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Prisma ORM Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you run `prisma migrate dev` without a schema file?

You run the command prisma migrate dev in your Next.js project but you forgot to create or specify a schema.prisma file. What will happen?

APrisma throws an error saying it cannot find the schema file.
BPrisma creates a default schema file automatically and runs migration.
CThe command runs but skips migration silently.
DThe command runs successfully and creates an empty migration.
Attempts:
2 left
💡 Hint

Think about what Prisma needs to know before it can create migrations.

📝 Syntax
intermediate
2:00remaining
Which Prisma schema datasource block correctly connects to a PostgreSQL database?

Choose the correct datasource block for connecting Prisma to a PostgreSQL database.

A
datasource db {
  provider = "postgresql"
  url      = "DATABASE_URL"
}
B
datasource db {
  provider = "postgres"
  url      = env("DATABASE_URL")
}
C
datasource db {
  provider = "pg"
  url      = env("DATABASE_URL")
}
D
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}
Attempts:
2 left
💡 Hint

The provider name must match Prisma's expected string exactly.

state_output
advanced
2:00remaining
What is the output of this Prisma client query in Next.js?

Given the following Prisma client code in a Next.js API route, what will be the output if the database has no users?

NextJS
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();

export default async function handler(req, res) {
  const users = await prisma.user.findMany();
  res.json({ count: users.length, users });
}
A{"count":0,"users":[]}
B{"count":0,"users":null}
C{"count":null,"users":null}
DAn error is thrown because the user table is empty.
Attempts:
2 left
💡 Hint

Think about what findMany() returns when no records exist.

🔧 Debug
advanced
2:00remaining
Why does this Prisma client query throw a runtime error?

Consider this Prisma client query in a Next.js app:

const user = await prisma.user.findUnique({ where: { id: 123 } });
console.log(user.name);

Why might this code throw an error?

ABecause the <code>id</code> field must be a string, not a number.
BBecause <code>findUnique</code> returns null if no user with id 123 exists, so accessing <code>name</code> causes a TypeError.
CBecause <code>findUnique</code> requires a second argument specifying fields to select.
DBecause Prisma client methods must be called inside a React component.
Attempts:
2 left
💡 Hint

What happens if no record matches the query?

🧠 Conceptual
expert
2:00remaining
What is the main benefit of using Prisma's generated client in a Next.js app?

Why do developers prefer using Prisma's generated client instead of writing raw SQL queries in Next.js applications?

AIt automatically scales the database server based on app traffic without configuration.
BIt replaces the need for a database by storing data in memory.
CIt provides type-safe database queries that catch errors during development and improve code reliability.
DIt allows writing SQL queries directly inside React components without any setup.
Attempts:
2 left
💡 Hint

Think about how Prisma helps with code safety and developer experience.