0
0
NestJSframework~20 mins

Why Prisma offers type-safe database access in NestJS - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Prisma Type-Safety Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How does Prisma ensure type safety in database queries?
Prisma generates types based on your database schema. What is the main benefit of this for developers?
AIt automatically encrypts all database data for security.
BIt prevents runtime errors by catching type mismatches during development.
CIt allows writing raw SQL queries without any checks.
DIt disables type checking to improve performance.
Attempts:
2 left
💡 Hint
Think about how knowing data types early helps avoid mistakes.
component_behavior
intermediate
2:00remaining
What happens if you try to assign a wrong type to a Prisma query result?
Consider this NestJS code using Prisma Client: const user = await prisma.user.findUnique({ where: { id: 1 } }); What will happen if you try to assign user.name (a string) to a variable declared as a number?
NestJS
const user = await prisma.user.findUnique({ where: { id: 1 } });
const age: number = user.name;
AThe code will run but user.name will be converted to a number automatically.
BThe app will crash at runtime with a type error.
CPrisma will ignore the type mismatch and assign the value.
DTypeScript will show a type error during development.
Attempts:
2 left
💡 Hint
Think about when TypeScript checks types.
📝 Syntax
advanced
2:00remaining
Which Prisma query correctly uses type-safe filtering for a user email?
You want to find a user by email using Prisma Client in NestJS. Which code snippet is type-safe and correct?
Aconst user = await prisma.user.findUnique({ where: { email: null } });
Bconst user = await prisma.user.findUnique({ where: { email: 12345 } });
Cconst user = await prisma.user.findUnique({ where: { email: 'test@example.com' } });
Dconst user = await prisma.user.findUnique({ where: { email: true } });
Attempts:
2 left
💡 Hint
Check the expected type of the email field in the schema.
🔧 Debug
advanced
2:00remaining
Why does this Prisma query cause a TypeScript error?
Look at this code snippet: const posts = await prisma.post.findMany({ where: { published: 'yes' } }); Why does TypeScript show an error here?
NestJS
const posts = await prisma.post.findMany({ where: { published: 'yes' } });
AThe 'published' field expects a boolean, but a string was given.
BThe 'published' field does not exist in the schema.
CPrisma Client does not support findMany queries.
DThe 'where' clause must be empty for findMany.
Attempts:
2 left
💡 Hint
Check the data type of the 'published' field in your Prisma schema.
state_output
expert
2:00remaining
What is the output type of this Prisma query in NestJS?
Given this Prisma Client query: const user = await prisma.user.findUnique({ where: { id: 5 } }); What is the type of 'user' in TypeScript?
NestJS
const user = await prisma.user.findUnique({ where: { id: 5 } });
AUser | null
Bnull
CUser
Dany
Attempts:
2 left
💡 Hint
Consider what happens if no user with id 5 exists.