Recall & Review
beginner
What is Prisma Client in the context of NestJS?
Prisma Client is an auto-generated database client that lets you easily read and write data in your database using simple and type-safe JavaScript or TypeScript code within a NestJS application.
Click to reveal answer
beginner
How do you typically inject Prisma Client into a NestJS service?
You create a PrismaService that extends PrismaClient and mark it as injectable. Then you inject PrismaService into other services via constructor injection to access database methods.
Click to reveal answer
beginner
What method would you use to find a single record by its unique ID using Prisma Client?
You use the
findUnique method with a where clause specifying the unique ID, for example: prisma.user.findUnique({ where: { id: 1 } }).Click to reveal answer
intermediate
Why is Prisma Client considered type-safe?
Because Prisma Client generates TypeScript types based on your database schema, it helps catch errors early by providing autocomplete and compile-time checks when you write queries.
Click to reveal answer
intermediate
How do you handle database connection cleanup in Prisma Client within a NestJS app?
You override the
onModuleDestroy lifecycle hook in your PrismaService to call this.$disconnect(), ensuring the database connection closes properly when the app stops.Click to reveal answer
Which method in Prisma Client is used to create a new record?
✗ Incorrect
The correct method to create a new record in Prisma Client is create().
How do you access Prisma Client inside a NestJS service?
✗ Incorrect
The best practice is to create a PrismaService that extends PrismaClient and inject it into services.
What does the findUnique() method require to find a record?
✗ Incorrect
findUnique() requires a where clause specifying a unique field like id or email.
Which lifecycle hook is used in NestJS to disconnect Prisma Client on app shutdown?
✗ Incorrect
onModuleDestroy is used to clean up resources like database connections.
Why is Prisma Client preferred over raw SQL queries in NestJS?
✗ Incorrect
Prisma Client offers type safety and simpler query syntax compared to raw SQL.
Explain how you set up and use Prisma Client in a NestJS service.
Think about dependency injection and how PrismaClient methods are accessed.
You got /4 concepts.
Describe how Prisma Client ensures type safety and why it matters.
Consider how TypeScript helps prevent mistakes.
You got /4 concepts.